Solved

Round up or down a sum

Posted on 2008-10-07
5
287 Views
Last Modified: 2012-06-22
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
Comment
Question by:markmchugh
5 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 22658709
$rounded = round($original/1000, 1);
0
 
LVL 40

Expert Comment

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

will return the number as you want.


0
 
LVL 5

Expert Comment

by:jericotolentino
ID: 22658727
Here, try this:
<?php

$number = 998;

echo number_format($number/1000, 1);

?>

Open in new window

0
 
LVL 40

Accepted Solution

by:
RQuadling 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;

}

Open in new window

0
 

Author Closing Comment

by:markmchugh
ID: 31503797
top reply...lol

thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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

16 Experts available now in Live!

Get 1:1 Help Now