Here’s some more fun with BigDecimal. Use Lucee 6 and turn on “Precise Math” in the admin before running this:
<cfdump eval="1/3"> <!--- string; this never goes into a numeric var --->
<cfset foobar = 1/3> <!--- this is going into a numeric var --->
<cfdump eval="foobar"> <!--- dump of that numeric var --->
The cfdump results are:
string 0.3333333333333333333333333333333333
number 0.3333333333333333
So why do we get 34 places after the decimal when the expression is evaluated as a string and never goes through or into any numeric variable, but only 16 places when it does?
I think I know why, it’s probably because internally, Java handles BigDecimals as strings. However, I’d think because Lucee apparently has code to limit accuracy to 16 places in numeric variables, it’d also have code to limit it to the same 16 places when a numeric variable isn’t involved.
It’s probably rare-to-never that this will present a problem to any of us (how often do you do math with hard-coded string literals like this?) but it’s good to be aware of it.
OS: Linux
Java Version: 11.0.11
Tomcat Version: 8.0.36
Lucee Version: 6.1.0.243
2 posts - 1 participant