note 76448 deleted from function.number-format by cmb

From: Date: Sun, 13 Jan 2019 10:44:18 +0000
Subject: note 76448 deleted from function.number-format by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210052@lists.php.net to get a copy of this message
Note Submitter: user at example dot net ---- The following function converts a string into Float or Integer while taking the given or locale number format into account. <?php function strtonumber( $str, $dec_point=null, $thousands_sep=null ) { if( is_null($dec_point) || is_null($thousands_sep) ) { $locale = localeconv(); if( is_null($dec_point) ) { $dec_point = $locale['decimal_point']; } if( is_null($thousands_sep) ) { $thousands_sep = $locale['thousands_sep']; } } $number = (float) str_replace($dec_point, '.', str_replace($thousands_sep, '', $str)); if( $number == (int) $number ) { return (int) $number; } else { return $number; } } ?>

« previous php.notes (#210052) next »