note 91848 added to function.trim

From: Date: Mon, 29 Jun 2009 05:45:37 +0000
Subject: note 91848 added to function.trim
Groups: php.notes 
Request: Send a blank email to php-notes+get-157656@lists.php.net to get a copy of this message
As an improvement to the zero trimming notes from 'rifter at cox dot net' and 'chris dot cowart at gmail dot com' four years ago, I tweaked their code so that it will avoid trimming integers: <?php function strip_trailing_zeros($num) { if( $num && is_float($num+1) ) return rtrim(rtrim($num, 0), '.'); else return $num; } ?> Note that my version only removes trailing zeros, as that is what I required. e.g. 0.034500 becomes 0.0345. To remove leading zeros as well, you only need change the inner most 'rtrim' to 'trim'. ---- Server IP: 117.55.229.1 Probable Submitter: 202.130.197.238 ---- Manual Page -- http://www.php.net/manual/en/function.trim.php Edit -- https://master.php.net/note/edit/91848 Del: integrated -- https://master.php.net/note/delete/91848/integrated Del: useless -- https://master.php.net/note/delete/91848/useless Del: bad code -- https://master.php.net/note/delete/91848/bad+code Del: spam -- https://master.php.net/note/delete/91848/spam Del: non-english -- https://master.php.net/note/delete/91848/non-english Del: in docs -- https://master.php.net/note/delete/91848/in+docs Del: other reasons-- https://master.php.net/note/delete/91848 Reject -- https://master.php.net/note/reject/91848 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157656) next »