RE: [PHP] Stupid question
| From: | Robert V. Zwink | Date: | Thu, 02 May 2002 15:59:25 +0000 |
| Subject: | RE: [PHP] Stupid question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95704@lists.php.net to get a copy of this message | ||
When I run:
$number = 0.023884057998657;
echo round($number, 3);
echo number_format($number, 3);
Both function output "0.024", both functions round the last digit. This is
contrary to the example in the manual which shows this:
$number = 1234.5678;
// english notation without thousands seperator
$english_format_number = number_format($number, 2, '.', '');
// 1234.56
http://www.php.net/manual/en/function.number-format.php
My output for the above is:
1234.57 not 1234.56
I'm using PHP Version 4.0.6
I would consider using the following to truncate a number if you do not want
to round. There may be a better way, but this seems to work fine.
substr($number, 0,strpos($number, ".")+4);
Robert V. Zwink
http://www.zwink.net
-----Original Message-----
From: Craig Vincent [mailto:2bunnyhop@rogers.com]
Sent: Thursday, May 02, 2002 5:54 AM
To: Liam MacKenzie; php-general@lists.php.net
Subject: RE: [PHP] Stupid question
> I have a script that outputs this:
> 0.023884057998657
>
> What's the command to make it shrink down to this:
> 0.023
>
>
> I thought it was eregi() something, but I forgot. sorry
It depends on what you need.
If you want to round the number off to 3 decimal points use the round()
function. However if you don't want to round and instead just want to
truncate the number, the number_format() function would be what you need.
Sincerely,
Craig Vincent
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php