系统函数 MathLib.round 将数字或表达式四舍五入到最接近的值(例如,四舍五入到最接近的千位)并返回结果。
MathLib.round( numericField mathLibNumber in [, powerOf10 mathLibInteger in ]) returns (result mathLibTypeDependentResult)
MathLib.round(numericExpression anyNumericExpression in returns (result mathLibTypeDependentResult)
如果在计算中使用了超过 31 位,并且如果 EGL 在开发时无法确定违例,则在运行时会发生数字溢出。
不能将 MathLib.round 与余数运算符(%)配合使用。
如果未指定 powerOf10,则 MathLib.round 将四舍五入到 result 中的小数位数。
integer 被定义为具有 INT 类型或者具有以下等效类型:BIN 类型,长度为 9 并且不带小数位。
在下面的示例中,项 balance 被四舍五入为最接近的千:
balance = 12345.6789; rounder = 3; balance = MathLib.round(balance, rounder); // The value of balance is now 12000.0000
在下面的示例中,使用 rounder 值 -2 来将 balance 四舍五入为带有两个小数位:
balance = 12345.6789; rounder = -2; balance = mathLib.round(balance, rounder); // The value of balance is now 12345.6800
相关概念
EGL 函数的语法图
相关参考
EGL 库 MathLib