在 azure 逻辑应用程序中,我将千克转换为磅,我需要将该结果四舍五入为两位小数。
Expression : mul(float(variables('total_weight')) , 2.20462262185)
Result : 1.102311310925
Expected Result : 1.10
最佳答案
我对数字进行四舍五入的解决方法是使用 formatNumber()
函数 fixed-point format 。所以你的代码将如下所示:
formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2')
最后一个参数中的格式字符串 - 'F2' - 其中 2 指定小数位。定点格式默认为两位小数,因此您也可以只使用“F”。
我可以看到您正在另一个对象变量的属性上使用它,所以就像 George 提到的那样,您需要将结果包装在 float()
函数中:
float(formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2'))
关于azure - 如何在azure逻辑应用程序中将 float 四舍五入为小数点后两位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55133794/