note 15001 modified in function.pi.php by jmcastagnetto

From: Date: Thu, 23 Aug 2001 21:06:37 +0000
Subject: note 15001 modified in function.pi.php by jmcastagnetto
Groups: php.notes 
Request: Send a blank email to php-notes+get-17048@lists.php.net to get a copy of this message
[Editor's note: for a cleaner and more sane solution to display of floating point numbers, see number_format() and/or round(), apparently the contributor of this note was not aware of those functions] I don't like this pi function. Perhaps in the next version of PHP it could be modified such that you can calculate pi out to a user-defined decimal point. Such as echo pi(2); outputting "3.14" or similar. Here's my code though: /* Calculate pi out to a certain decimal place - limited to how far the original pi() command goes out in the first place */ $pi = substr(pi(), 0,4); echo $pi; /* This example will output "3.14" Note that the substr is at 0,4 because it already counts the "3" and the "." */ http://www.php.net/manual/en/function.pi.php.php

« previous php.notes (#17048) next »