vipo
1
I’m trying to use decimal.Decimal in report scripting, but it’s not returning what I expect:

IN REPORT:

test = decimal.Decimal(72)/decimal.Decimal(7)

returns 10.3

IN SCRIPT CONSOLE:

print(decimal.Decimal(72)/decimal.Decimal(7))

returns 10.28571428571428571428571429

Can someone explain the reason for this ?

How are you ‘confirming’ your return value? Text fields in reporting will round values for display.

It’s working as I would expect on my end, even with different mechanism to create the decimal:

```
from java.math import BigDecimal, MathContext
data["bigDecimal"] = BigDecimal(72).divide(BigDecimal(7), MathContext.DECIMAL128)
import decimal
data["decimal"] = decimal.Decimal(72) / decimal.Decimal(7)
data["double"] = 72.0 / 7
```

The number format of each example is set to force arbitrary precision:

vipo
5
Thanks for those examples.

Both “bigDecimal” and “double” work, but “decimal” just won’t work.

I made the exact same test as you, so I don’t know what’s going on.

Anyways, I can make use of the other two.

thanks again.

1 Like