Front page | perl.perl5.porters | Postings from April 2000

## Re[2]: [ID 20000420.006] rounding floating numbers by *print

From:
jpeacock
Date:
April 21, 2000 08:18
Subject:
Re[2]: [ID 20000420.006] rounding floating numbers by *print
Message ID:
0004219563.AA956330946@univpress.com
```On a related topic, I am putting the finishing touches on a module which will
deal with the floating point/rounding issues completely in many normal
situations.  I have already written and distributed Math::Currency, which deals
with currency values as integers, using strict financial style rounding.  I have
been using it in a production environment for nearly a year now.

I have now (mostly) generalized that to be Math::FixedPrecision, which will
allow arbitrary precision to be maintained, without either rounding errors or
floating point nonsense (e.g., what is 100/9?).  I will then turn Math::Currency
into a wrapper and use the Posix Locale data to use the appropriate currency
display.  I foresee Math::FixedPrecision to also be useful in scientific
situations, where the result of a calculation should be no more accurate than
the least accurate datum.

Watch CPAN for an announcement soon...

John Peacock

Subject:    Re: [ID 20000420.006] rounding floating numbers by *printf i
Author: Ronald J Kimball <rjk@linguist.dartmouth.edu>
Date:       4/21/2000 10:48 AM

On Fri, Apr 21, 2000 at 03:04:20PM +0900, TOMITA Shigenari wrote:

> Return value of sprintf( "%2.0f", 0.5 ) is 0!
> But *printf for the value 1.5 works great!
> Many numbers are also rounded badly.
> You can play adding some 0's and 1 after 0.5,
> say 0.501 or 0.5000000000000001.  :}
>

% perldoc -q round

=head2 Does Perl have a round() function?  What about ceil() and floor()?
Trig functions?

```
• Re[2]: [ID 20000420.006] rounding floating numbers by *print by jpeacock

nntp.perl.org: Perl Programming lists via nntp and http.