作業#5.3 公式計算,比方寫梯形面積的 function

我還是經常記不起Float和Double的區別。所以我寫了兩個func 去提醒自己。

import UIKitfunc calculateTrapezoidArea (top: Float, bottom: Float, height: Float) -> Float {let result = (top + bottom) * height / 2print("This \(result) is actually inaccurate.")return result}func calculateTrapezoidAreaInDouble (top: Double, bottom: Double, height: Double) -> Double {let result = (top + bottom) * height / 2print("Now this \(result) is the real answer.")return result}calculateTrapezoidArea(top: 22222222.2, bottom: 55555555.5, height: 44444444.4)calculateTrapezoidAreaInDouble(top: 22222222.2, bottom: 55555555.5, height: 44444444.4)

--

--