0

我正在从 AWS S3 存储桶中读取 MuleSoft 中的 Excel (.xlsx) 文件,一旦我从 S3 存储桶中获取该文件,我就会得到如下 excel 文件的数据:

 %dw 2.0
output application/json

---

payload.parts pluck (value,key,index) -> 
        {
            (key) : { (read(value.content, 'application/xlsx'))} 
        }

问题是,文件12.535中有一个值,被读取为12.53499999。这会在舍入时产生问题,因为理想情况下,当我对小数进行四舍五入时,我应该得到值12.54,但正因为如此,.5349999我得到的值是12.53

如何确保 Mule 读取正确的值或解析正确的值?

使用 Mule 运行时 4.3.0。

4

2 回答 2

0

尝试将类型转换为字符串,然后返回到数字,例如:


 %dw 2.0
output application/json

---

payload.parts pluck (value,key,index) -> 
        {
            (key) : { ((read(value.content, 'application/xlsx')) as String {format: "0:00"}) as Number 

于 2021-06-16T12:01:12.227 回答
0

与excel类似的问题,已通过将值类型转换为数字然后转换为字符串格式来解决它

例如

{
 "Key" : value as Number as String { format: "##0.00" }
}

当真正有小数时,这保持了精度。

于 2021-07-10T05:57:51.273 回答