From:

Date:

January 28, 2002 23:52Subject:

Re: decimal pointMessage ID:

3C560329.8090101@ihcc.ccStuart Clark wrote: > Hi, > 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 > > Regards > Stuart Clark hm let me take a shot at this one my $digits = 4536233; $digits =~ m/(\d\d)$/; #I was going to inline this, but not sure of return value splice ( split ( //, $digits ), -2, 2, ( "." . $1) ) ); that should work, probably not worth it thought (I just opened the llama book and picked the first function that looked good and worked from that ^.^ anyway, the reason your example didn't work is because sprintf will truncate decimals from a floating point number. printf("%5.2f",$varname); #prints 123.12 if the var containted 123.1231525 since you had created a var containing integers (actually you created a string, it just turned it into numbers on demand), it didn't have anything to add for the decemil part.Thread Previous | Thread Next

- RE: decimal point by Darren Simpson
- Re: decimal point by Motherofperls
- decimal point by Stuart Clark
- Re: decimal point by Shawn
- Re: decimal point by John W. Krahn
- Re: decimal point by Leon
- Re: decimal point by Curtis Poe
**Re: decimal point**by sfritz- RE: decimal point by Darren Simpson
- decimal point by Stuart Clark
- Re: decimal point by sachin balsekar

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

Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About