Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Coldfusion evaluate these numbers to not be equal?

Why does coldfusion 8 evaluate 47.0000 * 15.40 eq 723.8 as false?

<cfset test = false />
<cfset a = 47.0000 />
<cfset b = 15.40 />
<cfset c = 723.8 />

<cfif (a * b) eq c>
  <cfset test = true />
</cfif>

<cfdump "#test#">

Test is output as false.

like image 354
Jason M Avatar asked Dec 06 '22 09:12

Jason M


1 Answers

You can use PrecisionEvaluate() to have CF use BigDecimals to do the math.

<cfset test = false />
<cfset a = 47.0000 />
<cfset b = 15.40 />
<cfset c = 723.8 />

<cfif PrecisionEvaluate(a * b) eq c>
  <cfset test = true />
</cfif>

<cfdump var="#test#" abort="true">

This results in the expected answer of true.

like image 104
Busches Avatar answered Jan 06 '23 01:01

Busches