Since round() is a maths routine, it will return the most approx. value of your 0.02388.. in 3 decimal digits. If you just want to return the first 3 digits after the decimal use the string routines suggested by Rober Zwink or : $number = $number*1000; // 23.884**** $number = floor($number); // 23 You can also see http://www.php.net/manual/en/function.floor.php and http://www.php.net/manual/en/function.ceil.php for what they do.
for a more general routine which will return any no of digits after decimal: $multiplier = pow(10, $noOfDigitsAfterDecimal); // 10^3 $number = $number*$multiplier; $number = floor($number); > 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:[EMAIL PROTECTED]] > Sent: Thursday, May 02, 2002 5:54 AM > To: Liam MacKenzie; [EMAIL PROTECTED] > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -Pushkar S. Pradhan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php