CF rounding issues
This is an issue I have on CF2016, but I've tried CF Fiddle and it's the same result on all versions, so I presume it's not a bug.
I noticed that calculations were not rounding correctly, for example if the calculation gave a result of 7.875 and I used NumberFormat to round it to two decimal places, I would have expected it to round up to 7.88
After a lot of playing around, and a few conversations with ChatGTP 🙂 I hacked around and found something unusual, if I change the value to a string, within the NumberFormat, it works.
Here is the code for the two tests with and without the ToString. Notice the different in rounding. Am I missing something? It gives me the right answer and I can't seem to break it, but it appears to be an odd way to go about things
<CFOUTPUT>
<b>Test 1</b>
<br>
Before rounding: #aff_payment#
<br>
After NumberFormat rounding: <b>#NumberFormat(aff_payment,"9999999.99")#</b>
<br><br>
<b>Test 2</b>
<br>
Before rounding: #aff_payment#
<br>
After NumberFormat rounding with ToString: <b>#NumberFormat(ToString(aff_payment),"9999999.99")#</b>
</CFOUTPUT>
Result
Test 1
Before rounding: 7.875
After NumberFormat rounding: 7.87
Test 2
Before rounding: 7.875
After NumberFormat rounding with ToString: 7.88
