Jump to content

Recommended Posts

Hi Mate,

 

thanks for that! i did this:

 

<?php

$low_value = 2.99;
$high_value = 5.99;

$percent = ($low_value / $high_value) * 100;

$p = number_format($percent);

print "You have saved $p%!";

?>

 

it gives me 50% saving is it ok to round it using number format do you think?

 

cheers mate

 

Graham

use round() to round up, or ceil() to round down.

 

number_format() is for large numbers to put the comma in after every 3 digits. like 1,000,000

 

Regards ACE

 

floor() rounds down. 

ceil() rounds up. 

round() rounds to nearest int.

 

<?php
for ($x = 1.1; $x < 2; $x += .1) {
   echo "[$x] floor " . floor($x) . " | ceil " . ceil($x) . " | round " . round($x) . "<br />";     
}
?>

 

output:

[1.1] floor 1 | ceil 2 | round 1

[1.2] floor 1 | ceil 2 | round 1

[1.3] floor 1 | ceil 2 | round 1

[1.4] floor 1 | ceil 2 | round 1

[1.5] floor 1 | ceil 2 | round 2

[1.6] floor 1 | ceil 2 | round 2

[1.7] floor 1 | ceil 2 | round 2

[1.8] floor 1 | ceil 2 | round 2

[1.9] floor 1 | ceil 2 | round 2

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.