Solved

Change 88.5454675463 to 88.55

Posted on 1999-01-16
5
176 Views
Last Modified: 2010-03-05
Hi....
$var = 88.5454675463;
#How do I change it so that.....
$var = 88.55; #2 decimal places
regards
0
Comment
Question by:rickyr
  • 2
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1210147
$var = sprintf"%.2f",$var;
0
 
LVL 1

Expert Comment

by:essuu
ID: 1210148
One easy way of doing this is:

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


0
 
LVL 3

Author Comment

by:rickyr
ID: 1210149
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
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 1210150
$var = sprintf"%.2f",$var;
#or
use POSIX;
$var = floor($var*100+0.5)/100;


see also:
perldoc -q round
0
 
LVL 3

Author Comment

by:rickyr
ID: 1210151
Thanks for the extra info, ozo.
cheers
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now