Req #79471 [NEW]: new function

From: Date: Mon, 13 Apr 2020 09:48:49 +0000
Subject: Req #79471 [NEW]: new function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226549@lists.php.net to get a copy of this message
From: festuc at lestudi dot com Operating system: any PHP version: 7.4.5RC1 Package: Unknown/Other Function Bug Type: Feature/Change Request Bug description:new function Description: ------------ --- From manual page: https://php.net/function.number-format --- Your number_format don't trim unnecesary zeros at left integer part or rigth decimal part. Humans brain read 58 58.1 when you put 00058.0000, 0058.1000 So, why no have a function for write 58 or 58.1 directly with a function? Test script: --------------- <?php function number_format_trim($value,$maxdecimal=0,$decimalsing='.',$thousandsing=','){ if (is_numeric($value)){ $value=number_format($value,$maxdecimal,'.','');//to change input type to string $i=-1; if (strpos($value,'.'))while (substr($value,$i)==0){ $i--; $maxdecimal--; } else $maxdecimal=0; return number_format($value,$maxdecimal,$decimalsing,$thousandsing); } } //example code: $decimalsing=','; //french mode $thousandsing=' '; $a = array (10000/3,10.15000,'00058.0000',1.01000,'pastafarism','1001.00100',30.05,25/2,'0.2500','potato'); foreach ($a as $w){ unset($o); $o=number_format_rtrim($w,5,$decimalsing,$thousandsing); if(isset($o)) echo "$w: $o"; else echo "$w is not a number"; echo '<br/>'; } ?> result is: 3333.3333333333: 3 333,33333 10.15: 10,15 00058.0000: 58 1.01: 1,01 pastafarism is not a number 1001.00100: 1 001,001 30.05: 30,05 12.5: 12,5 0.2500: 0,25 potato is not a number Expected result: ---------------- a new function Actual result: -------------- number_format do what need to do, but sometimes we need trim unnecesary zeros at rigth too -- Edit bug report at https://bugs.php.net/bug.php?id=79471&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79471&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79471&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79471&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79471&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79471&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79471&r=support Expected behavior: https://bugs.php.net/fix.php?id=79471&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79471&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79471&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79471&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79471&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79471&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79471&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79471&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79471&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79471&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79471&r=mysqlcfg

« previous php.bugs (#226549) next »