<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1036705" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1036705</link>
    <description></description>
    <language>en</language>
          <item>
    <title>This is an old post, so I&#039;m</title>
    <link>https://www.webmaster-forums.net/serverside-scripting/how-typecast-perl#comment-1251195</link>
    <description> &lt;p&gt;This is an old post, so I&#039;m writing an update to it so that you will know that there have been solutions in Perl for this for quite some time:&lt;/p&gt;
&lt;p&gt;c:\temp&amp;gt;perl -e &quot;use Math::BigFloat; my $a = Math::BigFloat-&amp;gt;new(q|10.01|);&lt;br /&gt;
print $a-&amp;gt;bsub(10);&quot;&lt;br /&gt;
0.01&lt;/p&gt;
&lt;p&gt;When looking for solutions in Perl, use search.cpan.org or perlmonks.org.&lt;/p&gt;
 </description>
     <pubDate>Fri, 30 Jul 2010 05:47:27 +0000</pubDate>
 <dc:creator>InfiniteSilence</dc:creator>
 <guid isPermaLink="false">comment 1251195 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/how-typecast-perl#comment-1211213</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;timjpriebe;211199 wrote:&lt;/strong&gt; This is a financial calculation, and I don&#039;t really want to lose a penny on each transaction that happens like that. There&#039;s not many exactly like that, but still...&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Ah, then you might want to follow the advice in &lt;a href=&quot;http://perldoc.perl.org/perlop.html#Floating-point-Arithmetic-floating-point-floating-point-float-real&quot; class=&quot;bb-url&quot;&gt;perlop&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote:&lt;br /&gt;
Rounding in financial applications can have serious implications, and the rounding method used should be specified precisely. In these cases, it probably pays not to trust whichever system rounding is being used by Perl, but to instead implement the rounding function you need yourself.
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;There may be a reliable third-party library to that effect, too.&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;timjpriebe;211199 wrote:&lt;/strong&gt; The big problem is happening when floating points aren&#039;t calculated correctly. Perl is saying at one point that 10.01 - 10 = .00999999999999997, or something like that.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That is actually a &#039;correct&#039; floating-point calculation.  You can round the result to two decimal places like so: [incode]printf(&quot;%.2f&quot;, 10.01-10);[/incode].  (But note the preceding caveat!)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Fri, 01 Dec 2006 11:33:50 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1211213 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/how-typecast-perl#comment-1211199</link>
    <description> &lt;p&gt;The big problem is happening when floating points aren&#039;t calculated correctly. Perl is saying at one point that 10.01 - 10 = .00999999999999997, or something like that. This is a financial calculation, and I don&#039;t really want to lose a penny on each transaction that happens like that. There&#039;s not many exactly like that, but still...&lt;/p&gt;
&lt;p&gt;If I understand correctly what you&#039;re suggesting, I would end up getting back 0 still.&lt;/p&gt;
 </description>
     <pubDate>Fri, 01 Dec 2006 06:12:50 +0000</pubDate>
 <dc:creator>timjpriebe</dc:creator>
 <guid isPermaLink="false">comment 1211199 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/how-typecast-perl#comment-1211158</link>
    <description> &lt;p&gt;You could change its printed representation to a float by using sprintf: [incode]sprintf(&quot;%f&quot;, int($thenumber));[/incode] and reuse the result.  Unless [incode]use integer;[/incode] is in force, all arithmetic will be carried out in floating point anyway.&lt;/p&gt;
&lt;p&gt;Details: &lt;a href=&quot;http://perldoc.perl.org/perlnumber.html&quot; class=&quot;bb-url&quot;&gt;perlnumber&lt;/a&gt;, &lt;a href=&quot;http://perldoc.perl.org/perlop.html#Integer-Arithmetic-integer&quot; class=&quot;bb-url&quot;&gt;perlop&lt;/a&gt;, &lt;a href=&quot;http://perldoc.perl.org/functions/sprintf.html&quot; class=&quot;bb-url&quot;&gt;sprintf&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
 </description>
     <pubDate>Thu, 30 Nov 2006 17:17:47 +0000</pubDate>
 <dc:creator>Abhishek Reddy</dc:creator>
 <guid isPermaLink="false">comment 1211158 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
