Jump to content

Archived

This topic is now archived and is closed to further replies.

quillspirit

rounding decimals?

Recommended Posts

I know I can round to a whole number with [code]ceil[/code] - but how can I round the just the hundredth? (Second number)...

Like 1.33333333333333
to
1.33
?

Thanks for the help :)

Share this post


Link to post
Share on other sites
Just remember:

[code]
<?php

// ceil rounds up
echo ceil("1.00001");
// will print out 2

// floor rounds down
echo ceil("1.99999");
// will print out 1

?>
[/code]

Share this post


Link to post
Share on other sites
Heres a nice little example for you.

[code]
<?php
$computer_price=ceil("1.9999");
$computer_price=sprintf("\$%01.3f",$computer_price);

echo " Please Pay $computer_price for your pc";
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.