0

I am reading an Excel (.xlsx) file in MuleSoft from AWS S3 bucket and once I have the file from S3 bucket, I get the data of the excel file like this :

 %dw 2.0
output application/json

---

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

the problem is, there is a value in file 12.535, which is being read as 12.53499999. Which creates a problem in rounding because ideally when I round up the decimal I should get value 12.54 but instead because of that .5349999I get value as 12.53.

How can I make sure Mule reads correct value or parses a correct value?

using Mule runtime 4.3.0.

8
  • Are you certain that the actual value in the field is not actually 12.53499999 but because of the formatting on Excel you see it rounded to two decimals?
    – aled
    Commented Jun 15, 2021 at 12:29
  • yes, I actually enter the value manually and there isn't any formatting in excel cell, I made sure of that too. I am still not sure what could cause this. Commented Jun 15, 2021 at 12:30
  • What's the Mule version? Did you install any patches?
    – aled
    Commented Jun 15, 2021 at 12:34
  • No I don't have any patches, we are running lates mule version. Versioning is also not a problem since we have scheduled calls with Mule architects to review what we ve done (Due to the nature of the contract of our company with SF) Commented Jun 15, 2021 at 12:36
  • Is the value coming from the of the script you shared, or there is some further operation after that?
    – aled
    Commented Jun 15, 2021 at 12:53

2 Answers 2

0

Try typecasting to string then back to number such as this:


 %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 

1
  • I will try this and let you know. Commented Jun 16, 2021 at 12:01
0

Similar issue with excel, Had solved it by type casting value to number then to String format

E.g.

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

This maintained precision when genuinely there's a decimal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.