round函数语法:
round(number,digits)
参数:
number,要四舍五入的数,digits是要小数点后保留的位数
如果 digits 大于 0,则四舍五入到指定的小数位。 如果 digits 等于 0,则四舍五入到最接近的整数。 如果 digits 小于 0,则在小数点左侧进行四舍五入。
如果round函数只有参数number,等同于digits 等于 0。
返回值:
四舍五入后的值
举例:
round(3.1415926,2)=3.14;
round(3.1415926,3)=3.142;
select round(193,-2)from dual; 200
select round(193,-1)from dual;190
select round(193,-3)from dual;0
Round函数出错处理
Round函数返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果。可是当保留位跟着的即使是5,有可能进位,也有可能舍去,机会各50%。这样就会造成在应用程序中计算有误。下面这个函数能真正实现四舍五入功能,用以取代Round函数。round函数(7)
PublicFunctionRoundToLarger(dblInputAsDouble,intDecimalsAsInteger)AsDouble '执行Round()函数,有可能进位 '也有可能舍去
DimstrFormatStringAsString'格式化字符串
'如果是“0”,则返回“0”,否则进行适当的格式化: IfdblInput<>0Then strFormatString="#."&String(intDecimals,"#") RoundToLarger=Format(dblInput,strFormatString) Else RoundToLarger=0 EndIf EndFunction
round函数如果 num_digits 大于 0(零),则将数字四舍五入到指定的小数位数。
如果 num_digits 等于 0,则将数字四舍五入到最接近的整数。
如果 num_digits 小于 0,则将数字四舍五入到小数点左边的相应位数。
若要始终进行向上舍入(远离 0),请使用 ROUNDUP 函数。
若要始终进行向下舍入(朝向 0),请使用 ROUNDDOWN 函数。
若要将某个数字四舍五入为指定的倍数(例如,四舍五入为最接近的 0.5 倍),请使用 MROUND 函数。[2]
ROUND ( numeric_expression , length [ ,function ] ) [3]