Hi, All,

I am struggling with a number precision problem. Ideally, I would like to see every number that is calculated in my script (through division, multiplication, whatever...) automatically limited to 4 numbers to the right of the decimal point. According to this:-

http://perldoc.perl.org/Math/BigFloat.html

I should be able to manage that requirement through this command:-

Math::BigFloat->precision(-4);

...but I cannot get this to work at all. Has anyone tried to define a global setting like this before? If you didn't use Math::BigFloat, what was the alternative?

A simple example is below. Note that a *lot* of calculations are being exercised in the real script, so I would really like to get a global setting working.

use Math::BigFloat; Math::BigFloat->precision(-4); for ($m = 1; $m <= 3; $m++) { for ($n = 1; $n <= 3; $n++) { $x = $m * $n * rand(3); print ("$x "); } print ("\n"); }
Thanks,

Fiddler42


In reply to Math::BigFloat question (precision) by fiddler42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.