note 77037 deleted from function.number-format by cmb

From: Date: Tue, 13 Nov 2018 11:38:02 +0000
Subject: note 77037 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209690@lists.php.net to get a copy of this message
Note Submitter: eb1024 at gmail dot com ---- To address the problems number_format has when dealing with big numbers I've created my own Number_Format method, it acts the same way as number_format and takes the same arguments but deals with numbers as strings solving the problems above referred. (The other methods are available at http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/) function Number_Format($number, $decimal_precision = 0, $decimals_separator = '.', $thousands_separator = ',') { if ($this->Is_Negative($number)) { $negative = true; $number = str_replace('-', '', $number); } $number = explode('.', str_replace(' ', '', $number)); $number[0] = str_split(strrev($number[0]), 3); $total_segments = count($number[0]); for ($i = 0; $i < $total_segments; $i++) { $number[0][$i] = strrev($number[0][$i]); } $number[0] = implode($thousands_separator, array_reverse($number[0])); if ($negative === true) { $number[0] = '-' . $number[0]; } if (!empty($number[1])) { $number[1] = $this->Round($number[1], $decimal_precision); } $number = implode($decimals_separator, $number); return $number; } I hope this is useful for someone!

« previous php.notes (#209690) next »