Posted by: prajapatinilesh | September 20, 2007

PHP Round Off Decimal or Convert to Decimal Point

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

Advertisements

Responses

  1. tnx.. this info helps me a lot

  2. Thanks, simple and clean example.

  3. THANK YOU

  4. Thanks a lot for this! ive searched for days! God bless u!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: