/// <summary> /// 实现数据的四舍五入法 /// </summary> /// <param name="v">要进行处理的数据</param> /// <param name="x">保留的小数位数</param> /// <returns>四舍五入后的结果</returns> public decimal Round(decimal v, int x)…
在处理一些数据时,我们希望能用“四舍五入”法实现,但是C#采用的是“四舍六入五成双”的方法,如下面的例子,就是用“四舍六入五成双”得到的结果: double d1 = Math.Round(1.25, 1);//1.2double d2 = Math.Round(1.24, 1);//1.2double d3 = Math.Round(1.26, 1);//1.3double d4 = Math.Round(1.35, 1);//1.4 为了用C#来实现“四舍五入”,我写了下面的函数: 代码 /…
c# 四舍五入.上取整.下取整 Posted on 2010-07-28 12:54 碧水寒潭 阅读(57826) 评论(4) 编辑 收藏 在处理一些数据时,我们希望能用“四舍五入”法实现,但是C#采用的是“四舍六入五成双”的方法,如下面的例子,就是用“四舍六入五成双”得到的结果: double d1 = Math.Round(1.25, 1);//1.2double d2 = Math.Round(1.24, 1);//1.2double d3 = Math.Round(1.26, 1);//…
1. 向上取整使用: Math.ceil() Math.ceil(0.1); Math.ceil(1.9); 2. 向下取整使用: Math.floor() Math.floor(0.1); Math.floor(1.9); 3. 四舍五入取整使用: Math.round() Math.round(0.1); Math.round(1.9); 4. 保留n位小数使用: Number().toFixed(n) Number(2.134).toFixed(2); // 2.13 Number(2.1…
[四舍五入取整截取] select round(54.56,0) [向下取整截取] SELECT floor(54.56) [向上取整截取]  SELECT   ceiling(13.15)…
import math #向上取整print "math.ceil---"print "math.ceil(2.3) => ", math.ceil(2.3)print "math.ceil(2.6) => ", math.ceil(2.6) #向下取整print "\nmath.floor---"print "math.floor(2.3) => ", math.floor(2.3)pr…
import math f = 11.2 print math.ceil(f) #向上取整 print math.floor(f) #向下取整 print round(f) #四舍五入 #这三个函数的返回结果都是浮点型…
Math.Round:四舍六入五取整 Math.Ceiling:向上取整,只要有小数都加1 Math.Floor:向下取整,总是舍去小数…
SELECT CEILING(23.5/4)'向上取整' ---6 :SELECT FLOOR(23.5/4)'向下取整' ---5 :SELECT ROUND(23.5/4,1)'四舍五入' --5.90000:…
对于数据的取整是经常需要考虑的 现在总结如下 #include<iostream> #include<cmath> using namespace std; int main() { double a=1.5; cout<<ceil(a)<<endl; //向上取整 cout<<floor(a)<<endl; //向下取整 cout<<round(a)<<endl; //四舍五入 //不使用函数 cout<…