Strange round result with certain number

Lucee Version: Lucee 5.4.3.2

When trying this example below, for the ‘c’ value, it seems that 89.565 does not round up to 89.57 as it’s supposed to do…

<cfset a=89.545>
<cfset b=89.555>
<cfset c=89.565>
<cfset d=89.575>

<cfoutput>
#round(a,2)#<br>
#round(b,2)#<br>
#round(c,2)#<br>
#round(d,2)#<br>
</cfoutput>

Result :
89.55
89.56
89.56
89.58

In lucee 6 this is not the case.

Did you try: PrecisionEvaluate() :: Lucee Documentation

Hi andreas, same result when using precisionEvaluate()

<cfoutput>
#PrecisionEvaluate("round(a,2)")#<br>
#PrecisionEvaluate("round(b,2)")#<br>
#PrecisionEvaluate("round(c,2)")#<br>
#PrecisionEvaluate("round(d,2)")#<br>
</cfoutput>

result :
89.55
89.56
89.56
89.58

Related ticket in Jira : [LDEV-3158] - Lucee

1 Like

PrecisionEvaluate() would be for math equations to stop binary to decimal conversion errors.
Follow to LDEV-2863 bug and you will see my rounding test program.
numberformat() seems to be the best to round.
Lucee 6 fixed most of the problems. I think I see one error from trycf.com for Lucee 6. I guess I will look into it.
ACF still isn’t very good either.

1 Like

Thanks for the reply, kabutotx. However, with numberformat() , there is another range of numbers that are not accurate when using this function. For example, 237453.525 will return 237453.52, not 237453.53

Bummer. That example also breaks Lucee 6. I will try to look at 6 and maybe add a bug report. I will have to re-setup my system to compile Lucee.

I think Lucee 5 is only getting regression and security fixes, so it won’t be fixed in 5.

1 Like