note 111397 added to function.number-format

From: Date: Fri, 15 Feb 2013 19:21:32 +0000
Subject: note 111397 added to function.number-format
Groups: php.notes 
Request: Send a blank email to php-notes+get-193648@lists.php.net to get a copy of this message
I came into a need to show two decimal places, but the desire to drop the decimal portion off if it is zero. This function is a direct replacement for number_format: <?PHP function number_format_clean($number,$precision=0,$dec_point='.',$thousands_sep=',') { RETURN trim(number_format($number,$precision,$dec_point,$thousands_sep),'0'.$dec_point); } ?> Example: <?PHP echo number_format_clean(25.00,2); echo number_format_clean(25.52,2); echo number_format_clean(50.10,2); echo number_format_clean(05.50,2); ?> Outputs: 25 25.52 50.1 5.5 Good for weight conversions (1 oz vs. 1.00 oz). Feels less "automated." The above will trim all insignificant zeros from both ends of the string, though I'm not sure I've ever seen leading zeros returned. ---- Server IP: 64.71.164.2 Probable Submitter: 208.95.30.82 ---- Manual Page -- http://php.net/manual/en/function.number-format.php Edit -- https://master.php.net/note/edit/111397 Del: integrated -- https://master.php.net/note/delete/111397/integrated Del: useless -- https://master.php.net/note/delete/111397/useless Del: bad code -- https://master.php.net/note/delete/111397/bad+code Del: spam -- https://master.php.net/note/delete/111397/spam Del: non-english -- https://master.php.net/note/delete/111397/non-english Del: in docs -- https://master.php.net/note/delete/111397/in+docs Del: other reasons-- https://master.php.net/note/delete/111397 Reject -- https://master.php.net/note/reject/111397 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193648) next »