C O M M E N T S
Comment display is being revamped. We apologize for the delay.
|
Validation
[rcverbeek]
[Wednesday, Dec 12, 2007 07:47 AM] |
|
I have been searching for a bug in our webshop for a few hours now, only to find out that it is a bug by Coldfusion. The peace of code where it all goes wrong resembles the code by Sean.
We have coded a custom rounding function that takes (among others) these two parameters as input:
<cfargument name="InputValue" required="true" type="numeric">
<cfargument name="RoundingPrecision" type="numeric" required="true">
We want to get rid of the decimals by multiplying by a large value, in our case 100,000:
<cfset ModFactor = 100000>
<cfset InputModValue = InputValue * ModFactor>
<cfset RoundingModPrecision = RoundingPrecision * ModFactor>
We then calculate the modulo value:
<cfset RestModValue = InputModValue Mod RoundingModPrecision>
If we use an input value of 1.13 and roundingprecision of 0.01: we expect:
InputModValue = 113000
RoundingModPrecision = 1000
and RestModValue = 0.
However in Coldfusion the latter one is 999!
Typing 113000 mod 1000 directly will yield the correct result, but by using the intermediate variables it goes wrong.
I had to use an explicit ROUND() on the two calculations to make it work again.
|
|