2014-10-26 135 views
-2

我已經編寫了代碼來計算點之間的距離。爲了讓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') 

德爾福2010

+0

請重讀你的問題,而假裝你是我們的,誰對你的問題沒有上下文。除了猜測之外,你認爲它是可以回答的嗎? – 2014-10-26 20:11:15

+1

你能告訴我們你正在使用什麼編程語言並向我們展示代碼嗎? – Zenexer 2014-10-26 20:11:28

+0

我已經更新了這個問題 – Lucas999 2014-10-26 20:15:24

回答

0
>>> some_float = 10.10101010101 
>>> some_2_decimal_float = round(some_float, 2) 
>>> some_2_decimal_float 
10.10 
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 
相關問題