develooper Front page | perl.beginners | Postings from February 2002

Re: Number Truncation/Rounding

Thread Previous | Thread Next
From:
Brett W. McCoy
Date:
February 13, 2002 11:53
Subject:
Re: Number Truncation/Rounding
Message ID:
Pine.LNX.4.43.0202131500270.19376-100000@chapelperilous.net
On Wed, 13 Feb 2002, Balint, Jess wrote:

> Hello all. I have a script that uses alot of data and calculates a
> cumulative percent of this data. That cumulative percent should be 100.00 at
> the end. What I get is:
>
> 99.9999999999998
>
> I need to truncate this to 2 decimal places and hopefully round it to
> 100.00. Thanks in advance.

~$ perl -e 'printf "%.2f", 99.9999999999998'
100.00

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
 "Someone's been mean to you! Tell me who it is, so I can punch him tastefully."
-- Ralph Bakshi's Mighty Mouse


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About