tracker issue : CF-3956970

select a category, or use search below
(searches all categories and all time range)
Title:

Calculation bug

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/NotABug

Reporter/Name(from Bugbase): Julien de Cardaillac / Julien de Cardaillac (Julien de Cardaillac)

Created: 03/20/2015

Components: Language

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final /

Priority/Frequency: Major / Most users will encounter

Locale/System: English / Win All

Vote Count: 0

Problem Description:

When we do int() after a calculation result the value is calculted on the approx.

Steps to Reproduce:
<cfoutput>

<cfset nb = 3.8-3.0 />
#nb#<br/>
<cfset nb = nb*10 />
#NumberFormat(nb,"0.00000000000000000000000000000000000000000000000000000000000000")#<br/>
#Int(nb)#<br/>
#Int(8.0)#

</cfoutput>

Actual Result:
0.8
7.99999999999999800000000000000000000000000000000000000000000000
7
8

Expected Result:
0.8
8.00000000000000000000000000000000000000000000000000000000000000
8
8

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3956970

External Customer Info:
External Company:  
External Customer Name: Julien
External Customer Email:

Attachments:

Comments:

Int() is correctly functioning, it always results in the closest integer smaller than the number. You are confusing it's functionality with that of Round()
Comment by External U.
7984 | March 20, 2015 09:34:00 AM GMT
but (3.8-3)*10 = 8.0 not 7.99999
Comment by External U.
7985 | March 20, 2015 09:36:07 AM GMT
Hi Julien, Please try precisionEvaluate() around the floating point arithmetic. writeOutput(numberFormat(precisionEvaluate(3.8-3.0), "0.00"));//returns 0.80 Thanks!, -Aaron
Comment by External U.
7986 | May 14, 2015 07:01:08 PM GMT