[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 225
  • Last Modified:

Change 88.5454675463 to 88.55

Hi....
$var = 88.5454675463;
#How do I change it so that.....
$var = 88.55; #2 decimal places
regards
0
rickyr
Asked:
rickyr
  • 2
  • 2
1 Solution
 
ozoCommented:
$var = sprintf"%.2f",$var;
0
 
essuuCommented:
One easy way of doing this is:

$var=(int($var*100)/100);


0
 
rickyrAuthor Commented:
Hi.....
If $var = 85.568 then the 6 doesn't get rounded up to a 7.
But even if it did work, Ozo was here first, so he should get the points. (sorry).
Where are you ozo???????
regards
0
 
ozoCommented:
$var = sprintf"%.2f",$var;
#or
use POSIX;
$var = floor($var*100+0.5)/100;


see also:
perldoc -q round
0
 
rickyrAuthor Commented:
Thanks for the extra info, ozo.
cheers
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now