Thread View: ba.php
3 messages
3 total messages
Started by agent-blue
Tue, 07 Nov 2000 00:00
Rounding
Author: agent-blue
Date: Tue, 07 Nov 2000 00:00
Date: Tue, 07 Nov 2000 00:00
15 lines
1003 bytes
1003 bytes
I am writing a script that is dividing numbers as a result I can get a very long number as it contains many numbers after the decimal point I know you can use floor() to drop everything after the decimal point and ceil() to round 13.2 up to 14 but how can I get 2.8603515625 to be rounded to 2.86 ? -- Will Tatam www.netmindz.co.uk
Re: Rounding
Author: Brian Tkatch
Date: Tue, 07 Nov 2000 00:00
Date: Tue, 07 Nov 2000 00:00
24 lines
1337 bytes
1337 bytes
On Tue, 7 Nov 2000 18:36:26 -0000, "agent-blue" <agent_blue_17m@yahoo.co.uk> wrote: >I am writing a script that is dividing numbers > >as a result I can get a very long number as it contains many numbers after >the decimal point > >I know you can use floor() to drop everything after the decimal point and >ceil() to round 13.2 up to 14 >but how can I get > >2.8603515625 to be rounded to 2.86 ? > I believe the round function does just that with its second parameter. <URL:http://www.php.net/manual/function.round.php>. If you actually wanted to use floor or ceil then just move the decimal point with the power of ten. $Num = (Floor($Num * 100)/100) Brian
Re: Rounding
Author: Rod Apeldoorn
Date: Thu, 09 Nov 2000 00:00
Date: Thu, 09 Nov 2000 00:00
23 lines
1391 bytes
1391 bytes
"agent-blue" <agent_blue_17m@yahoo.co.uk> wrote in message news:8u9i3s$jq3$1@plutonium.btinternet.com... > I know you can use floor() to drop everything after the decimal point and > ceil() to round 13.2 up to 14 > but how can I get > > 2.8603515625 to be rounded to 2.86 ? Hey Will, Try the round function (good in PHP 3 and 4). <?php $num1 = 2.8603515625; $num2 = round( $num1, 2); echo $num2; ?> http://www.php.net/manual/function.round.php Rod Apeldoorn rod@canowhoopass.com http://www.canowhoopass.com/
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads