2013-03-29 21 views
2

我想申請string.Format()這樣一種方式,它執行截斷而不是四捨五入。例如如何使用string.Format()截斷而不是圓?

string.Format("##", 46.5); // output is 47, but I want 46 
string.Format("##.#", 46.55); // output is 46.6, but I want 46.5 
+0

http://stackoverflow.com/questions/164926/c-sharp-how-do-i-round-a-decimal-value-截斷以2位小數爲單位輸出一個pa – Niventh

回答

0

使用Math.Truncate之前格式化輸出

+0

這是「截斷」(與n),btw –

+0

這不是他想46.55是46.5,我想。 Math.Truncate將返回46. –

+0

var v = Math.Truncate(46.5); v.ToString(「##。#」)//給出46 – realnero

相關問題