不知道如何舍入到小数点后两位

时间:2014-10-26 20:08:43

标签: delphi delphi-2010

我已编写代码来计算出点之间的距离。为了让rFinal四舍五入到小数点后两位,我需要键入什么内容?

rtotaldist := arcCos(sin(degtorad(rhouselat))*sin(degtorad(rcachelat))
+cos(degtorad(rhouselat))*
cos(degtorad(rcachelat))*cos(degtorad(rhouselong-rcachelong)));
rfinal := rdistperdegree*rtotaldist;


pnlclose.Caption:=('That cache is exactly ' + floattostr(rfinal) + ' KM away')

Delphi 2010

2 个答案:

答案 0 :(得分:0)

>>> some_float = 10.10101010101
>>> some_2_decimal_float = round(some_float, 2)
>>> some_2_decimal_float
10.10

答案 1 :(得分:0)

许多语言提供带有第二个参数的循环函数;第二个参数指定了你在答案中喜欢的小数位数。

对于那些本质上不提供的语言,你可以这样做:

# I want 2 decimal places, so I'm going to multiply by 10^2
x = x * 100

# Now we round
x = round(x)

# Finally, we divide by 10^2, which is the number we used in the first line.
x = x / 100
相关问题