我想申請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
我想申請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
使用Math.Truncate
之前格式化輸出
這是「截斷」(與n),btw –
這不是他想46.55是46.5,我想。 Math.Truncate將返回46. –
var v = Math.Truncate(46.5); v.ToString(「##。#」)//給出46 – realnero
http://stackoverflow.com/questions/164926/c-sharp-how-do-i-round-a-decimal-value-截斷以2位小數爲單位輸出一個pa – Niventh