PHP Round Off Decimal or Convert to Decimal Point

Round a number up or down or Round off a floating decimal point number using PHP’s functions round(). Or convert a digit to a decimal point. Greate for shopping carts or time sheet programs.

Round Off Decimal

Round a number up or down or Round off a floating decimal point number using PHP’s functions round().

Example. round();
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?>

Convert to Decimal Point

Example. number_format();
$number = “28″;
$number = number_format($number, 2);
echo $number; // equals “28.00″
?>

For a good book on PHP, check out Beginning PHP4

One Response

  1. it was a great use to me..ty for the post

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Next Post » »