乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Math.Round四舍六入五成雙

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

      Math.Round四舍六入五成雙


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

      Math.Round這個(gè)函數(shù)的解釋是將值按指定的小數(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


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

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


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

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

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多