当前位置: 首页 > news >正文

墨刀做网站发布新闻

墨刀做网站,发布新闻,小程序代理设置,西安专业网站排名优化Math.Round()并不是严格意义上的是四舍五入函数。它默认的执行的是“银行家舍入”算法,即四舍六入五取偶。概括为:四舍六入五考虑、五后非零就进一,五后皆零看奇偶,五前为偶应舍去、五前为奇要进一。 当为5时,取离着最…

Math.Round()并不是严格意义上的是四舍五入函数。它默认的执行的是“银行家舍入”算法,即四舍六入五取偶。概括为:四舍六入五考虑、五后非零就进一,五后皆零看奇偶,五前为偶应舍去、五前为奇要进一

        当为5时,取离着最近的偶数。见下图:

               

测试代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MathRoundTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Math.Round(1234.5).ToString());  //输出:1234
            Console.WriteLine(Math.Round(1234.50).ToString());  //输出:1234
            Console.WriteLine(Math.Round(1235.5).ToString());  //输出:1236
            Console.WriteLine(Math.Round(1235.50).ToString());  //输出:1236
            Console.WriteLine("---------------------------------------------");

            Console.WriteLine(Math.Round(-1234.5).ToString());  //输出:-1234
            Console.WriteLine(Math.Round(-1234.50).ToString());  //输出:-1234
            Console.WriteLine(Math.Round(-1235.5).ToString());  //输出:-1236
            Console.WriteLine(Math.Round(-1235.5).ToString());  //输出:-1236
            Console.WriteLine("---------------------------------------------");

            Console.WriteLine(Math.Round(123.45, 1).ToString());  //输出:123.4
            Console.WriteLine(Math.Round(123.55, 1).ToString());  //输出:123.6
            Console.WriteLine("---------------------------------------------");


            Console.WriteLine(Math.Round(-123.45, 1).ToString());  //输出:-123.4
            Console.WriteLine(Math.Round(-123.55, 1).ToString());  //输出:-123.6
            Console.WriteLine("---------------------------------------------");

            Console.ReadLine();
        }
    }
}
 

如果要实现我们所需要的四舍五入,需要使用使用四舍五入策略参数:MidpointRounding.AwayFromZero  (当为5时,取远离0的数值)。

测试代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MathRoundTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Math.Round(1234.5,MidpointRounding.AwayFromZero).ToString());  //输出:1235
            Console.WriteLine(Math.Round(1234.50, MidpointRounding.AwayFromZero).ToString());  //输出:1235
            Console.WriteLine(Math.Round(1235.5, MidpointRounding.AwayFromZero).ToString());  //输出:1236
            Console.WriteLine(Math.Round(1235.50, MidpointRounding.AwayFromZero).ToString());  //输出:1236
            Console.WriteLine("---------------------------------------------");

            Console.WriteLine(Math.Round(-1234.5, MidpointRounding.AwayFromZero).ToString());  //输出:-1235
            Console.WriteLine(Math.Round(-1234.50, MidpointRounding.AwayFromZero).ToString());  //输出:-1235
            Console.WriteLine(Math.Round(-1235.5, MidpointRounding.AwayFromZero).ToString());  //输出:-1236
            Console.WriteLine(Math.Round(-1235.5, MidpointRounding.AwayFromZero).ToString());  //输出:-1236
            Console.WriteLine("---------------------------------------------");

            Console.WriteLine(Math.Round(123.45, 1, MidpointRounding.AwayFromZero).ToString());  //输出:123.5
            Console.WriteLine(Math.Round(123.55, 1, MidpointRounding.AwayFromZero).ToString());  //输出:123.6
            Console.WriteLine("---------------------------------------------");


            Console.WriteLine(Math.Round(-123.45, 1, MidpointRounding.AwayFromZero).ToString());  //输出:-123.5
            Console.WriteLine(Math.Round(-123.55, 1, MidpointRounding.AwayFromZero).ToString());  //输出:-123.6
            Console.WriteLine("---------------------------------------------");

            Console.ReadLine();
        }
    }
}
 

http://www.mnyf.cn/news/41567.html

相关文章:

  • 成都网页设计培训学校排名咖啡seo是什么意思
  • 为什么做网站费用贵软文推广营销
  • 如何做网站运营互联网广告推广是做什么的
  • wordpress免费教程视频教程厦门百度关键词seo收费
  • 做网站要租服务器长沙网站制作策划
  • 怎样制作免费的网站百度网站关键词排名查询
  • 用外链css做网站百度推广助手客户端
  • 开原网站建设河北网络科技有限公司
  • php网站上做微信支付功能网站建设价格
  • 蚌埠做网站有哪些公司郑州互联网公司排名
  • 免费网站建设推荐百度邮箱注册入口
  • 做外贸网站推广sem和seo是什么职业岗位
  • html5做网站的好处seo搜索引擎优化薪资水平
  • 无锡网站建设解决方案信息推广
  • 基金网站制作品牌营销策略分析
  • 天河区门户网站教育局板块广州企业网站建设
  • 兰州做公司网站现在搜什么关键词能搜到网站
  • 怎么做网站代理国外免费网站域名服务器查询
  • wordpress appdev teamseo优化外链平台
  • 上海网站建设价格chrome官方下载
  • 网站开发兼职合同seo编辑的工作内容
  • 如何快速用手机做网站百度网盘免费下载
  • 做网站一定需要服务器吗十大最靠谱教育培训机构
  • 如何做网站淘客推广138ip查询网域名解析
  • 注册网站获取网易邮箱安全码百度广告推广费用年费
  • 网站 需求分析深圳关键词优化公司哪家好
  • 龙华做网站的超能搜索引擎系统网站
  • 南京网站优化网站建设公司东莞整站优化推广公司找火速
  • 做播放器电影网站需要多少钱6网站链接交易
  • 响应式网站好吗sem与seo的区别