Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在azure逻辑应用程序中,如何将浮点数四舍五入为2个十进制数?_Azure_Rounding_Azure Logic Apps - Fatal编程技术网

在azure逻辑应用程序中,如何将浮点数四舍五入为2个十进制数?

在azure逻辑应用程序中,如何将浮点数四舍五入为2个十进制数?,azure,rounding,azure-logic-apps,Azure,Rounding,Azure Logic Apps,在azure逻辑应用程序中,我将千克转换为磅,我需要将结果四舍五入为两个十进制数字 目前,在逻辑应用程序中还没有通用的舍入解决方案。但是,您需要针对您的数据构建解决方案 这里有一种方法可以将小数四舍五入到2,以便于显示 if(contains('56789', substring(string(variables('math')),4,1)),substring(string(add(variables('math'),0.01)),0,4),substring(string(variable

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


目前,在逻辑应用程序中还没有通用的舍入解决方案。但是,您需要针对您的数据构建解决方案

这里有一种方法可以将小数四舍五入到2,以便于显示

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()
以返回float number。我用
2.20462262185
2.205622262185
测试了两次


目前,逻辑应用程序中仍然没有通用的舍入解决方案。但是,您需要针对您的数据构建解决方案

这里有一种方法可以将小数四舍五入到2,以便于显示

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()
以返回float number。我用
2.20462262185
2.205622262185
测试了两次


我对数字四舍五入的解决方法是使用函数。因此,您的代码如下所示:

formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2')
最后一个参数“F2”中的格式字符串,其中2指定小数位数。小数点后两位是定点格式的默认值,因此您也可以只使用“F”

我可以看到您正在另一个对象变量的属性上使用它,所以正如George提到的,您需要将结果包装在
float()
函数中:

float(formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2'))

我对数字四舍五入的解决方法是使用函数。因此,您的代码如下所示:

formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2')
最后一个参数“F2”中的格式字符串,其中2指定小数位数。小数点后两位是定点格式的默认值,因此您也可以只使用“F”

我可以看到您正在另一个对象变量的属性上使用它,所以正如George提到的,您需要将结果包装在
float()
函数中:

float(formatNumber(mul(float(variables('total_weight')) , 2.20462262185), 'F2'))