Try running this, and you'll see the problem:

<cfset c = 15.12 + 59.70 - 74.82 />
<cfoutput>
#c#<br />
#val(c)#
</cfoutput>

The reason is that floating point arithmetic is not exact.  You end up
with a very small error (1.42108547152E-014) that CF expresses as
scientific notation.  When you run val() on it, it strips the
exponent, so you're left with something that's 14 orders of magnitude
off of what the real result is.

cheers,
barneyb

On 12/6/05, sdaniels @ marketplacetech. com sdaniels @
marketplacetech. com <[EMAIL PROTECTED]> wrote:
> Create an empty .cfm and put this in it:
>
> <cfdump var="#val(15.12 + 59.70 - 74.82)#"/>
>
> As far as I can tell, 15.12 + 59.70 = 74.82, and 15.12 + 59.70 - 74.82 = 0.
>
> However, if I run the code above I get 1.42108547152. I have tried this on 
> three different servers, one being a 7.0.1, the others 6.1.
>

--
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 100 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:226257
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to