Warm tip: This article is reproduced from serverfault.com, please click

rounding-如何在azure逻辑应用程序中将浮点数四舍五入为2个小数?

(rounding - How to round off float number to 2 decimal numbers in azure logic apps?)

发布于 2019-03-13 03:14:43

在azure逻辑应用程序中,我将千克转换为磅,我需要将该结果四舍五入为两个十进制数字。

在此处输入图片说明

Expression : mul(float(variables('total_weight')) , 2.20462262185)

Result :  1.102311310925
Expected Result : 1.10
Questioner
Dinuka Wanasinghe
Viewed
0
George Chen 2019-03-13 13:59:06

到目前为止,Logic Apps中仍然没有通用的舍入解决方案。但是,你需要特定于数据的构建解决方案。

这是一种你可以将小数点后舍入到两位以用于显示目的的方法。

if(contains('56789', substring(string(variables('math')),4,1)),substring(string(add(variables('math'),0.01)),0,4),substring(string(variables('math')),0,4))

这种方式将返回字符串格式,你可以添加float()以返回浮点数。我用2.20462262185测试了两次2.20562262185

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明