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

Re: Number Truncation/Rounding

Thread Previous
From:
Jonathan E. Paton
Date:
February 13, 2002 10:35
Subject:
Re: Number Truncation/Rounding
Message ID:
20020213183547.25854.qmail@web14603.mail.yahoo.com
 --- "Balint, Jess" <JBalint@alldata.net> 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.

Easy.

$var = sprintf(".2f", $var);

Jonathan Paton
> 
> -- 
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>  

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Thread Previous


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