note 97042 deleted from function.number-format by cmb

From: Date: Sun, 08 Sep 2019 10:16:21 +0000
Subject: note 97042 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212124@lists.php.net to get a copy of this message
Note Submitter: isedc at yahoo dot com ---- Some programmers may have scripts that use the number_format function twice on a variable. However, if a number is 4 or more digits, using the function twice with only the decimals parameter will lose part of the value that follows the thousands separator. <?php $var = number_format(2234,2); $var = number_format($var,2); echo $var; # Expected Output: 2,234.00 # Actual Output: 2.00 ?> To fix, remove the thousands separator by setting the decimal point and thousands separator parameters like so: <?php $var = number_format(2234,2,'.',''); $var = number_format($var,2,'.',''); echo $var; # Expected Output: 2234.00 # Actual Output: 2234.00 ?> If it's 3 digits or less, then it works normally with only the decimals parameter since there is no thousands separator. <?php $var = number_format(123,2); $var = number_format($var,2); echo $var; # Expected Output: 123.00 # Actual Output: 123.00 ?>

« previous php.notes (#212124) next »