<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Beware ColdFusion Floating Point Integers</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/comment-page-1/#comment-185855</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Sun, 19 Jul 2009 16:52:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1027#comment-185855</guid>
		<description>Ograll,

Even just explicitly using java.math.BigDecimal (and BigInteger) is perfectly sufficient in most cases.  ColdFusion will treat it like any other java.lang.Number so you can use standard math operators on it and pass &quot;numeric&quot; type checks.  Just a matter of ensuring you&#039;re using an instance of it and it&#039;s methods when it matters, which can be difficult, since ColdFusion uses java.lang.Double for everything.  As such, you can START with floating point error if you&#039;re not careful.

In my example, using the string constructor to either &quot;Big&quot; class and then comparing would have been equally successful, but since simply comparing the strings I&#039;d be passing to the constructors also worked, it saves a pile of typing.  The moreso because I was actually comparing strings that just happened to be valid numbers (&lt;cfif s EQ repeatString(left(s, 1), len(s)&gt;).  Yay for implicit type conversions!</description>
		<content:encoded><![CDATA[<p>Ograll,</p>
<p>Even just explicitly using java.math.BigDecimal (and BigInteger) is perfectly sufficient in most cases.  ColdFusion will treat it like any other java.lang.Number so you can use standard math operators on it and pass "numeric" type checks.  Just a matter of ensuring you're using an instance of it and it's methods when it matters, which can be difficult, since ColdFusion uses java.lang.Double for everything.  As such, you can START with floating point error if you're not careful.</p>
<p>In my example, using the string constructor to either "Big" class and then comparing would have been equally successful, but since simply comparing the strings I'd be passing to the constructors also worked, it saves a pile of typing.  The moreso because I was actually comparing strings that just happened to be valid numbers (<cfif s EQ repeatString(left(s, 1), len(s)>).  Yay for implicit type conversions!</cfif></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ograll</title>
		<link>https://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/comment-page-1/#comment-185853</link>
		<dc:creator>Ograll</dc:creator>
		<pubDate>Sun, 19 Jul 2009 16:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1027#comment-185853</guid>
		<description>This is not a problem with just CF but floating point in general. Floating point is an approximation at best of the real numbers. There are very few numbers in the Real Line that can be exactly represented by Floating point, the rest get rounded at some point, consider pi, 1/3, or sqrt(2). In the examples you present you have past ability for the Significand of the floating point system to represent your numbers. One of the strange oddities of Floating point is that its accuracy goes down as the number moves away from 0 on the real line. As a matter of a fact when you hit the number 1 you have already passed 50% of the numbers that Floating point can represent.

Due to these factors most bank software avoids floating point, and if you want big numbers you need to get yourself a large number package.</description>
		<content:encoded><![CDATA[<p>This is not a problem with just CF but floating point in general. Floating point is an approximation at best of the real numbers. There are very few numbers in the Real Line that can be exactly represented by Floating point, the rest get rounded at some point, consider pi, 1/3, or sqrt(2). In the examples you present you have past ability for the Significand of the floating point system to represent your numbers. One of the strange oddities of Floating point is that its accuracy goes down as the number moves away from 0 on the real line. As a matter of a fact when you hit the number 1 you have already passed 50% of the numbers that Floating point can represent.</p>
<p>Due to these factors most bank software avoids floating point, and if you want big numbers you need to get yourself a large number package.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Krug</title>
		<link>https://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/comment-page-1/#comment-185491</link>
		<dc:creator>Jamie Krug</dc:creator>
		<pubDate>Thu, 16 Jul 2009 03:43:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1027#comment-185491</guid>
		<description>BTW, if you read my post at &lt;a href=&quot;http://bit.ly/3FyZnM&quot; rel=&quot;nofollow&quot;&gt;http://bit.ly/3FyZnM&lt;/a&gt;, you&#039;ll see that I solved my rounding issue in the same way: cast to string to &quot;lose&quot; the floating point representation. While I was at it, I had my round UDF also enable you to round to a specified decimal point.</description>
		<content:encoded><![CDATA[<p>BTW, if you read my post at <a href="http://bit.ly/3FyZnM" rel="nofollow">http://bit.ly/3FyZnM</a>, you'll see that I solved my rounding issue in the same way: cast to string to "lose" the floating point representation. While I was at it, I had my round UDF also enable you to round to a specified decimal point.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Krug</title>
		<link>https://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/comment-page-1/#comment-185490</link>
		<dc:creator>Jamie Krug</dc:creator>
		<pubDate>Thu, 16 Jul 2009 03:41:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1027#comment-185490</guid>
		<description>Yeah, I discovered a bug in the round() function a while back, which seems to be related. I blogged about it back in February (http://bit.ly/3FyZnM) and reported it to Adobe&#039;s &quot;wish/bug list&quot; back then. I just confirmed that the bug still exists in ColdFusion 9 beta 1 as well as OpenBD 1.1. Railo does not suffer this bug (neither 3.0 nor 3.1).

Basically, #round(4000.5)# outputs 4001, and you&#039;d expect #round(4.0005*1000)# to output the same, but AdobeCF and OpenBD output 4000 for the latter.

FWIW, for your first example above, Railo 3.1.0.22 outputs neither what you&#039;d expect nor what Adobe CF outputs, but rather &quot;true true true true false true.&quot; This suggests that I might be able to find a similar round() function &quot;bug&quot; in Railo as well.

I guess all that is to say: you make a good point, Barney :) Beware of floating point representations in CFML!</description>
		<content:encoded><![CDATA[<p>Yeah, I discovered a bug in the round() function a while back, which seems to be related. I blogged about it back in February (<a href="http://bit.ly/3FyZnM" rel="nofollow">http://bit.ly/3FyZnM</a>) and reported it to Adobe's "wish/bug list" back then. I just confirmed that the bug still exists in ColdFusion 9 beta 1 as well as OpenBD 1.1. Railo does not suffer this bug (neither 3.0 nor 3.1).</p>
<p>Basically, #round(4000.5)# outputs 4001, and you'd expect #round(4.0005*1000)# to output the same, but AdobeCF and OpenBD output 4000 for the latter.</p>
<p>FWIW, for your first example above, Railo 3.1.0.22 outputs neither what you'd expect nor what Adobe CF outputs, but rather "true true true true false true." This suggests that I might be able to find a similar round() function "bug" in Railo as well.</p>
<p>I guess all that is to say: you make a good point, Barney :) Beware of floating point representations in CFML!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben Nadel</title>
		<link>https://www.barneyb.com/barneyblog/2009/07/15/beware-coldfusion-floating-point-integers/comment-page-1/#comment-185478</link>
		<dc:creator>Ben Nadel</dc:creator>
		<pubDate>Thu, 16 Jul 2009 00:51:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1027#comment-185478</guid>
		<description>I remember the first time I ran into number problems - trying to NumberFormat() the dollar amount for a merger in the billions of dollars. CF didn&#039;t care to treat that as a valid number :) Good to know there are easy work arounds to some of the number limitations. Thanks.</description>
		<content:encoded><![CDATA[<p>I remember the first time I ran into number problems &#8211; trying to NumberFormat() the dollar amount for a merger in the billions of dollars. CF didn't care to treat that as a valid number :) Good to know there are easy work arounds to some of the number limitations. Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
