<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: Compensating for loss of float accuracy in JavaScript?</title>
		<atom:link href="http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 04:40:01 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-32694</guid>
					<title><![CDATA[Compensating for loss of float accuracy in JavaScript?]]></title>
					<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-32694</link>
					<pubDate>Sat, 30 Jun 2007 17:45:49 +0000</pubDate>
					<dc:creator>nick rothwell / cassiel</dc:creator>

					<description>
						<![CDATA[
						<p>Here&#8217;s a little problemette I&#8217;m having: when I pass a float like  <br />
&#8220;4.53&#8243; into JavaScript from the Max world, it gets turned into 4.53 <br />
+noise digits. Internally as a constant in JavaScript, it&#8217;s fine.  <br />
(Example enclosed.)</p>
<p>I assume the noise digits are due to rounding (the number 4.5 is  <br />
fine, presumably because it has a precise IEEE representation). I  <br />
don&#8217;t know why it works internally in JS: perhaps that&#8217;s doing some  <br />
kind of symbolic interpretation.</p>
<p>So, my question is: how do I truncate or round the accuracy of  <br />
rendering floats into strings in JS? I couldn&#8217;t find anything in the  <br />
documentation regarding floating point formatting a la sprintf().</p>
<p>	&#8211; N.</p>
<p>
&#8212; Patcher file:</p>
<p>max v2;<br />
#N vpatcher 10 59 272 236;<br />
#P window setfont Monaco 9.;<br />
#P window linecount 1;<br />
#P newex 60 83 88 262153 js me-test.js;<br />
#P message 60 60 58 262153 foo 4.53;<br />
#P connect 0 0 1 0;<br />
#P pop;</p>
<p>&#8212; JS file (me-test.js):</p>
<p>function foo() {<br />
	post(&#8220;arg gives: &#8221; + arguments[0] + &#8220;n&#8221;);<br />
	post(&#8220;literal gives: &#8221; + 4.53 + &#8220;n&#8221;);<br />
}</p>
<p>
Nick Rothwell / Cassiel.com Limited<br />
<a href="http://www.cassiel.com" rel="nofollow">http://www.cassiel.com</a><br />
<a href="http://www.myspace.com/cassieldotcom" rel="nofollow">http://www.myspace.com/cassieldotcom</a><br />
<a href="http://www.loadbang.net" rel="nofollow">http://www.loadbang.net</a></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108029</guid>
					<title><![CDATA[Re: Compensating for loss of float accuracy in JavaScript?]]></title>
					<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108029</link>
					<pubDate>Sat, 30 Jun 2007 17:55:07 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>On 30 juin 07, at 19:45, Nick Rothwell wrote:</p>
<p>> So, my question is: how do I truncate or round the accuracy of  <br />
> rendering floats into strings in JS? I couldn&#8217;t find anything in  <br />
> the documentation regarding floating point formatting a la sprintf().</p>
<p>Somthing like that should work (no tested though):</p>
<p>function bang()<br />
{<br />
	var toto = 0.576528356;<br />
	post(toto.toFixed(3));<br />
}</p>
<p>ej</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108030</guid>
					<title><![CDATA[Re: Compensating for loss of float accuracy in JavaScript?]]></title>
					<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108030</link>
					<pubDate>Sat, 30 Jun 2007 18:33:30 +0000</pubDate>
					<dc:creator>Pierre Alexandre Tremblay</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108031</guid>
					<title><![CDATA[Re: Compensating for loss of float accuracy in JavaScript?]]></title>
					<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108031</link>
					<pubDate>Sat, 30 Jun 2007 18:58:58 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>On 30 juin 07, at 20:33, Pierre Alexandre Tremblay wrote:</p>
<p>> I always wonder: is it really a lost of resolution, or is it the  <br />
> opposite: we just see a 32 bit float being properly represented in  <br />
> 64-bit double float?</p>
<p>JS works with 64 bit double float. but for representing the number as  <br />
a string you usually need to display it with less precision.</p>
<p>ej</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108032</guid>
					<title><![CDATA[Re: Compensating for loss of float accuracy in JavaScript?]]></title>
					<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108032</link>
					<pubDate>Sat, 30 Jun 2007 19:18:23 +0000</pubDate>
					<dc:creator>nick rothwell / cassiel</dc:creator>

					<description>
						<![CDATA[
						<p>
On 30 Jun 2007, at 18:55, Emmanuel Jourdan wrote:</p>
<p>> 	var toto = 0.576528356;<br />
> 	post(toto.toFixed(3));</p>
<p>Cool &#8211; thanks. I&#8217;m sure I didn&#8217;t come across this when I dug through  <br />
the JS 1.5 docs I have here&#8230;</p>
<p>	&#8211; N.</p>
<p>
Nick Rothwell / Cassiel.com Limited<br />
<a href="http://www.cassiel.com" rel="nofollow">http://www.cassiel.com</a><br />
<a href="http://www.myspace.com/cassieldotcom" rel="nofollow">http://www.myspace.com/cassieldotcom</a><br />
<a href="http://www.loadbang.net" rel="nofollow">http://www.loadbang.net</a></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108033</guid>
					<title><![CDATA[Re: Compensating for loss of float accuracy in JavaScript?]]></title>
					<link>http://cycling74.com/forums/topic/compensating-for-loss-of-float-accuracy-in-javascript/#post-108033</link>
					<pubDate>Sat, 30 Jun 2007 23:08:57 +0000</pubDate>
					<dc:creator>Mattijs</dc:creator>

					<description>
						<![CDATA[
						<p>Moving this thread to the javascript forum, please direct your replies to the javascript list.</p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

