I’m trying to use decimal.Decimal in report scripting, but it’s not returning what I expect:
test = decimal.Decimal(72)/decimal.Decimal(7)
IN SCRIPT CONSOLE:
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)
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:
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.