note 115833 deleted from function.number-format by cmb

From: Date: Tue, 13 Nov 2018 11:41:15 +0000
Subject: note 115833 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209694@lists.php.net to get a copy of this message
Note Submitter: dont at spam dot me ---- The function rlerne posted does not work well in many cases: <?php function number_format_clean($number, $precision = 0, $dec_point = '.', $thousands_sep = ',') { return trim(number_format($number, $precision, $dec_point ,$thousands_sep), '0' . $dec_point); } ?> Fail examples: <?php number_format_clean(0.1, 2); // returns "1" number_format_clean(10.000001, 2); // returns "1" ?> This one is correct: <?php function number_format_clean($number, $precision = 0, $dec_point = '.', $thousands_sep = ',') { return rtrim(rtrim(number_format($number, $precision, $dec_point ,$thousands_sep), '0'), $dec_point); } ?>

« previous php.notes (#209694) next »