小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Math.Round四舍六入五成雙

 water簡愛 2015-11-18
Math.Round方法真正意義上的四舍五入

Math.Round四舍六入五成雙


不能直接調(diào)用Math.Round方法的,這可和Java的不一樣哦

Math.Round這個函數(shù)的解釋是將值按指定的小數(shù)位數(shù)舍入,并不就是四舍五入。這種舍入有時稱為就近舍入或四舍六入五成雙


C# code
Math.Round(0.4) //result:0
Math.Round(0.6) //result:1
Math.Round(0.5) //result:0
Math.Round(1.5) //result:2
Math.Round(2.5) //result:2
Math.Round(3.5) //result:4
Math.Round(5.5) //result:6
Math.Round(6.5) //result:6
Math.Round(8.5) //result:8
Math.Round(9.5) //result:10


可以看出 并不是四舍五入的   
其實在 VB, VBScript, C#, J#, T-SQL 中 Round 函數(shù)都是采用 Banker's rounding(銀行家舍入)算法,即四舍六入五取偶。事實上這也是 IEEE 規(guī)定的舍入標準。因此所有符合 IEEE 標準的語言都應該是采用這一算法的。

請調(diào)用 Math.Round(Decimal, MidpointRounding) 重載!~哦,原來還有重載的方法可用,MidpointRounding在兩個數(shù)字之間時如何舍入的規(guī)范,規(guī)范MidpointRounding中它有2個成員,一個是ToEven還有個是AwayFromZero。


C# code
//四舍五入 Math.Round(0.5,MidpointRounding.AwayFromZero)

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多