Product: CF 7 BugHunt User: Anonymous
[Switch Product] CFUG: None

Add and View Bug Comments at the bottom of the Element.
Title: Int() giving a number 1 less than expected BugID: 1352 Date Opened: 13-Jul-06
Created By:
Sean Sekora
Type: Function Element/Element: Int()
Severity: Unexpected Results Status: New/Unvalidated
Adobe BugID:

Description of bug:
Comments:
--->

A D D     Y O U R     C O M M E N T S     T O     T H I S     B U G

Please login to add comments to a bug


C O M M E N T S

Comment display is being revamped. We apologize for the delay.

Click on this to respond to the current comment 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.