Round up or down a sum

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?
markmchughAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
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;
}

Open in new window

0
 
Cornelia YoderArtistCommented:
$rounded = round($original/1000, 1);
0
 
Richard QuadlingSenior Software DeveloperCommented:
number_format(round($i_Value / 1000, 1), 1)

will return the number as you want.


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

Open in new window

0
 
markmchughAuthor Commented:
top reply...lol

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.