note 88463 added to function.bcscale

From: Date: Sun, 25 Jan 2009 17:00:38 +0000
Subject: note 88463 added to function.bcscale
Groups: php.notes 
Request: Send a blank email to php-notes+get-149757@lists.php.net to get a copy of this message
Good day, I made a little function to remove the excess zeroes after calculations.. it makes them cleaner and more presentable. <?php function DecimalClean($Input) { $Input=explode('.',$Input,2); if(!isset($Input[1])) $Input[1]=0; for($i=(strlen($Input[1])-1);$i>0;$i--) { if($Input[1]{$i}=='0') $Input[1]=substr($Input[1],0,-1); else break; } return(sprintf('%s%s',$Input[0],($Input[1]!='0')?".{$Input[1]}":'')); } BCScale(10); // allow 10 decimals $Sum = BCDiv(10,8); // make a calculation printf("Result #1: %s\n", $Sum); // 1.2500000000 printf("Result #2: %s\n", DecimalClean($Sum)); // 1.25 ?> Hope this helps, Nitrogen. ---- Server IP: 92.48.74.199 Probable Submitter: 86.163.201.19 ---- Manual Page -- http://www.php.net/manual/en/function.bcscale.php Edit -- https://master.php.net/note/edit/88463 Del: integrated -- https://master.php.net/note/delete/88463/integrated Del: useless -- https://master.php.net/note/delete/88463/useless Del: bad code -- https://master.php.net/note/delete/88463/bad+code Del: spam -- https://master.php.net/note/delete/88463/spam Del: non-english -- https://master.php.net/note/delete/88463/non-english Del: in docs -- https://master.php.net/note/delete/88463/in+docs Del: other reasons-- https://master.php.net/note/delete/88463 Reject -- https://master.php.net/note/reject/88463 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149757) next »