note 120921 deleted from function.number-format by cmb

From: Date: Tue, 13 Nov 2018 11:44:32 +0000
Subject: note 120921 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-209697@lists.php.net to get a copy of this message
Note Submitter: adrianTNT ---- Watch out for the default thousands separator when formatting number: $timer_start = 1491048291.5000; $timer_end = 1491048292.8000; $timer_start = number_format($timer_start, 3); $timer_end = number_format($timer_end, 3); echo ($timer_end - $timer_start); // this equals "0" and NOT "1.3", because ... number_format(1491048291.5000, 3) = "1,491,048,291.500"; while you might expect it to be: 1491048291.500 The "0" result is probably because you end up deducting two strings, not numbers; to get 1.3 from the above example you must specify empty thousands separator (after decimal character "."): number_format($timer_start, 3, '.', '');

« previous php.notes (#209697) next »