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

Re: decimal point

Thread Previous | Thread Next
From:
John W. Krahn
Date:
January 28, 2002 02:28
Subject:
Re: decimal point
Message ID:
3C5527D8.9A8BEE53@acm.org
Stuart Clark wrote:
> 
> Hi,

Hello,

> I am trying to move the decimal point 2 places to the the left.
> 
> Eg : To make 4536233 into 45362.33
> 
> I tried this
> $total = "4536233";
> $total = sprintf("%0.2f",$total);
> print "$total";
> But I get this
> 4536233.00
> 
> Can anyone help please

$ perl -le'
$total = 4536233; $total =~ s/(..)$/.$1/;
print $total;
$total = 4536233; substr $total, -2, 0, ".";
print $total;
'
45362.33
45362.33



John
-- 
use Perl;
program
fulfillment

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