note 26680 modified in ref.math by aidan
| From: | aidan@php.net | Date: | Sat, 26 Jun 2004 03:14:04 +0000 |
| Subject: | note 26680 modified in ref.math by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71711@lists.php.net to get a copy of this message | ||
I was looking for a truncate function. Not finding one, I wrote my own. Since it deals with
everything as a number, I imagine it's faster than the alternative of using string functions.
HTH...
<?php
function truncate ($num, $digits = 0) {
//provide the real number, and the number of
//digits right of the decimal you want to keep.
$shift = pow(10, $digits);
return ((floor($num * $shift)) / $shift);
}
?>
--was--
I was looking for a truncate function. Not finding one, I wrote my own. Since it deals with
everything as a number, I imagine it's faster than the alternative of using string functions.
HTH...
function truncate ($num, $digits = 0) {
//provide the real number, and the number of
//digits right of the decimal you want to keep.
$shift = pow(10, $digits);
return ((floor($num * $shift)) / $shift);
}
http://php.net/manual/en/ref.math.php