[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Change 88.5454675463 to 88.55

Posted on 1999-01-16
5
Medium Priority
?
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

650 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