Jump to content


Photo

rounding decimals?


  • Please log in to reply
4 replies to this topic

#1 quillspirit

quillspirit
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationOregon, USA

Posted 16 October 2006 - 06:35 AM

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

Like 1.33333333333333
to
1.33
?

Thanks for the help :)
Peace,
Shawn
Simple PHP

#2 cows

cows
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 October 2006 - 06:38 AM

I think..

round("1.33333333333333", 2);


#3 quillspirit

quillspirit
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts
  • LocationOregon, USA

Posted 16 October 2006 - 06:48 AM

*EDIT*

Thanks, that did the trick :)
Peace,
Shawn
Simple PHP

#4 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 16 October 2006 - 09:16 AM

Just remember:

<?php

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

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

?>

SA PHP Archives - www.phparchives.za.org

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 09:44 AM

Heres a nice little example for you.

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

echo " Please Pay $computer_price for your pc"; 
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users