Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a decimal point. 1

Status
Not open for further replies.

cb49747

MIS
Apr 23, 2002
181
0
0
US
I have a number 171500 It should be 1715.00 I have tried using this

Code:
   $field3 = sprintf("%.2f",$field3);

but it gives me this 171500.00

How do I add the decimal in the proper place?
 
That is what I have been doing. But was wondering if there was an easier way.
 
Dividing by 100 is probably the best way.

Alternatively,

Code:
[kirsle@firefly ~]$ perl
my $number = 171500;
print "Before: $number\n";
$number =~ s/(\d\d)$/.$1/;
print "After: $number\n";
__END__
Before: 171500
After: 1715.00

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Code:
$field3 = 171500;
$field3 = sprintf("%.2f",$field3/100);
print $field3;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Or:
Code:
substr( $field3, length( $field3 ) - 2, 0, '.' );
 
This is exactly what I was looking for.

$field3 = sprintf("%.2f",$field3/100);

I wanted to do it in one command rather than two.

Thanks

KevinADC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top