Math.Floor 总是舍去小数

            double result1 = Math.Floor(0.3);
            Console.WriteLine(result1);//result1显示0

            double result2 = Math.Floor(0.5);
            Console.WriteLine(result2);//result2显示0

            double result3 = Math.Floor(0.6);
            Console.WriteLine(result3);//result3显示0         

            Console.Read();    

原文地址:https://www.cnblogs.com/158-186/p/10894780.html

时间: 2024-07-31 23:50:44

Math.Floor 总是舍去小数的相关文章

JavaScript基础 Math.floor() 向下取整 小数部分不四舍五入了,有小数就舍去。小数再大,都舍

镇场诗: 清心感悟智慧语,不着世间名与利.学水处下纳百川,舍尽贡高我慢意. 学有小成返哺根,愿铸一良心博客.诚心于此写经验,愿见文者得启发.------------------------------------------ code: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=ut

js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结(转)

js中Math.round.parseInt.Math.floor和Math.ceil小数取整总结 Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整. 如: Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round(-1.5) //返回-1 Math.round(-5.8) //返回-6 二.

js中Math.round、parseInt、Math.floor和Math.ceil小数取整总结

Math.round.parseInt.Math.floor和Math.ceil 都可以返回一个整数,具体的区别请看下面的总结. 一.Math.round 作用:四舍五入,返回参数+0.5后,向下取整. 如: Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round(-1.5) //返回-1 Math.round(-5.8) //返回-6 二.parseInt 作用:解析一个字符串,并返回一个整数,这里可以简单理解成返回舍去参数的小数部分后的

Math.round、parseInt、Math.floor和Math.ceil小数取整小结

以前经常以代码中看到Math.round.parseInt和Math.floor这三个函数,虽然知道结果最后都是返回一个整数,但是对他们三者的区别还是不太清楚,今天就做一个小结. 一.Math.round 作用:四舍五入,返回最接近参数的整数,如果小数部分大于等于0.5,返回大于参数的最小整数,否则返回小于等于参数的最大整数. 如: Math.round(5.57) //返回6 Math.round(2.4) //返回2 Math.round(-1.5) //返回-1 二.parseInt 作用

C#取整函数Math.Round、Math.Ceiling和Math.Floor

1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) //0Math.Round(0.4) //0Math.Round(0.5) //0Math.Round(0.6) //1Math.Round(0.7) //1Math.Round(0.8) //1Math.Round(0.9) //1 说明:对于1.5,因要返回偶数,所以结果为2. 2.Math.Ce

python中的math.ceil(x)和math.floor(x)

一 math.ceil(x) import math 1.当x为正数时,只要x的小数部分>0就+1 x=5.01 print(math.ceil(x)) #6 x=5.9 print(maht.ceil(x)) #6 2.当x为负数时,舍去小数部分 x=-5.9 print(math.ceil(x)) #-5 x=-5.01 print(math.ceil(x)) #-5 二.math.floor(x) 1.当x为正数时,舍去小数部分 x=5.9 print(math.floor(x)) #5

Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?

Math.round(x) 四舍五入 加上0.5向下取整 Math.round(1.5) 2 Math.round(-11.5) -11 Math.round(-11.2) -10 Math.ceil(x) 不小于x的最小整数 Math.ceil(1.5) 2 Math.ceil(-1.5) -1 Math.floor(x) 返回小于等于x的最大整数 Math.floor(5.99)) 5 Math.floor(-5.99) -6 Math.random() 生成0和1之间的随机小数 Math.

Math ceil() Math.floor(),Math.round()用法

Math.ceil() Math.ceil(x) 参数: x:一个数值. 返回值:返回大于或等于x,并且与之最接近的整数. 注:如果x是正数,则把小数“入”:如果x是负数,则把小数“舍”. 例: <script type="text/javascript"> document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Ma

Math.round(),Math.ceil(),Math.floor()的区别

1.Math.round():根据“round”的字面意思“附近.周围”,类似四舍五入,但负数不一致 小数点后第一位<5 正数:Math.round(11.46)=11 负数:Math.round(-11.46)=-11 小数点后第一位>5 正数:Math.round(11.68)=12 负数:Math.round(-11.68)=-12 小数点后第一位=5 正数:Math.round(11.5)=12 负数:Math.round(-11.5)=-11 总结:(小数点后第一位)大于五全部加,等