真爱无限的知识驿站

学习积累技术经验,提升自身能力

.Net函数Math.Round你会用吗?

一直以为Math.Round就是四舍五入,谁知道没加参数,得到的结果就是有问题


测试代码:

void Main()
{
    string.Format("Round  {0} = {1}",2.4M,Math.Round(2.4M,0)).Dump();
    string.Format("Round  {0} = {1}",2.5M,Math.Round(2.5M,0)).Dump();
    string.Format("Round  {0} = {1}",2.6M,Math.Round(2.6M,0)).Dump();
    string.Format("Round  {0} = {1}",3.4M,Math.Round(3.4M,0)).Dump();
    string.Format("Round  {0} = {1}",3.5M,Math.Round(3.5M,0)).Dump();
    string.Format("Round  {0} = {1}",3.6M,Math.Round(3.6M,0)).Dump();
}

输出内容:

<< 1 >>

Powered By Z-BlogPHP 1.7.3

Copyright 2024-2027 pukuimin Rights Reserved.
粤ICP备17100155号