Solved

# Round up or down a sum

Posted on 2008-10-07
323 Views
Hi,
I want to round numbers to a specific format, to 1 decimal place, eg

1345 rounds to 1.3
998 rounds to 1.0
1190 rounds to 1.2 etc

can anybody help?
0
Question by:markmchugh
[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

LVL 27

Expert Comment

ID: 22658709
\$rounded = round(\$original/1000, 1);
0

LVL 40

Expert Comment

ID: 22658706
number_format(round(\$i_Value / 1000, 1), 1)

will return the number as you want.

0

LVL 5

Expert Comment

ID: 22658727
Here, try this:
``````<?php
\$number = 998;
echo number_format(\$number/1000, 1);
?>
``````
0

LVL 40

Accepted Solution

Richard Quadling earned 500 total points
ID: 22658918
yodercm, 998 will become 1 rather than the required 1.0

1345 becomes RAQ:1.3 yodercm:1.3 jericotolentino:1.3
998 becomes RAQ:1.0 yodercm:1 jericotolentino:1.0
1190 becomes RAQ:1.2 yodercm:1.2 jericotolentino:1.2

``````<?php
\$values = array(1345, 998, 1190);
foreach(\$values as \$value) {
echo \$value, ' becomes ',
'RAQ:', number_format(round(\$value / 1000, 1), 1), ' ',
'yodercm:', round(\$value / 1000, 1), ' ',
'jericotolentino:', number_format(\$value / 1000, 1),
PHP_EOL;
}
``````
0

Author Closing Comment

ID: 31503797

thanks
0

## Featured Post

Question has a verified solution.

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

### Suggested Solutions

MySQL limit and not so limited 13 60
assigning javascript variable to php variable 8 68
Code planning methods/tools? 5 56
How can I send attachment with mail 5 24
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
###### Suggested Courses
Course of the Month6 days, 7 hours left to enroll