azure - 如何在azure逻辑应用程序中将 float 四舍五入为小数点后两位?

标签 azure rounding azure-logic-apps

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

enter image description here

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/

相关文章:

azure - 设置触发器来监视新文件夹 Azure 逻辑应用

json - Azure 逻辑应用 - 多部分/表单数据失败

azure - 访问有状态服务

c# - 如何将十进制值四舍五入到最接近的 0.05 值?

Python - 如何在不四舍五入的情况下删除小数

azure - 可以在 Service Fabric 中运行逻辑应用和 Azure Functions(或等效功能)吗?

azure - 获取 Azure 中所有服务主体的证书状态,例如证书是否无效,以及最终它们在 Azure 中连接到的内容

azure - 在 Azure/AWS 中读/写快照

asp.net-mvc - 当 MVC 托管在 Azure 中时,为什么 MultipartFormDataContent 不起作用?

python - 四舍五入到6位有什么问题吗?