note 53651 added to function.number-format

From: Date: Wed, 08 Jun 2005 12:25:32 +0000
Subject: note 53651 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-90109@lists.php.net to get a copy of this message
You could use the following regular expression to divide a number into parts: $1-number without fractal part $2-fractal part $3-first 2 digits of the fractal part $4-rest of the fractal part the regex removes any leading and trailing symbols and leading zeros. It doesnt validate the number, so 12 41 is considered to be correct input! english notation: /^.*?[0]*([\d\s]+)(([\.][\d]{0,2})([\d]*))?.*?$/ french notation: /^.*?[0]*([\d\s]+)(([\,][\d]{0,2})([\d]*))?.*?$/ <?php // truncate the fractal part up to 2 digits of an "english number": $number = '01,234.50789'; $trunc = preg_replace( '/^.*?[0]*([\d\,]+)(([\.][\d]{0,2})([\d]*))?.*?$/', '$1$3', $number ); echo $trunc; ?> Outputs: 1,234.50 $number='e00012 41.100001e-4fasfd'; would output: 12 41.10 ---- Manual Page -- http://www.php.net/manual/en/function.number-format.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53651 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53651&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53651&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53651&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53651&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53651&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53651&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90109) next »