note 89475 added to function.floatval

From: Date: Tue, 10 Mar 2009 05:10:52 +0000
Subject: note 89475 added to function.floatval
Groups: php.notes 
Request: Send a blank email to php-notes+get-151673@lists.php.net to get a copy of this message
i noticed all (well, unless i missed something) the functions working with decimals destroy trailing decimal places. this function restores them in case you want to be able to display a consistent precision for users. function decimal($val, $precision = 0) { if ((float) $val) : $val = round((float) $val, (int) $precision); list($a, $b) = explode('.', $val); if (strlen($b) < $precision) $b = str_pad($b, $precision, '0', STR_PAD_RIGHT); return $precision ? "$a.$b" : $a; else : // do whatever you want with values that do not have a float return $val; endif; } ---- Server IP: 208.69.120.35 Probable Submitter: 96.40.107.9 ---- Manual Page -- http://www.php.net/manual/en/function.floatval.php Edit -- https://master.php.net/note/edit/89475 Del: integrated -- https://master.php.net/note/delete/89475/integrated Del: useless -- https://master.php.net/note/delete/89475/useless Del: bad code -- https://master.php.net/note/delete/89475/bad+code Del: spam -- https://master.php.net/note/delete/89475/spam Del: non-english -- https://master.php.net/note/delete/89475/non-english Del: in docs -- https://master.php.net/note/delete/89475/in+docs Del: other reasons-- https://master.php.net/note/delete/89475 Reject -- https://master.php.net/note/reject/89475 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151673) next »