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

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

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?
0
markmchugh
Asked:
markmchugh
1 Solution
 
Cornelia YoderArtistCommented:
$rounded = round($original/1000, 1);
0
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
markmchughAuthor Commented:
top reply...lol

thanks
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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