note 54473 deleted from function.trim by hholzgra

From: Date: Thu, 02 Aug 2012 12:23:04 +0000
Subject: note 54473 deleted from function.trim by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189640@lists.php.net to get a copy of this message
Note Submitter: chris dot cowart at gmail dot com ---- Here's a neat function to trim off extraneous zeros and the decimal, leaving important numbers intact: <?php function clean_num($num){ return trim(trim($num, '0'), '.'); } echo clean_num('06000.3050'); echo clean_num('500.00'); ?> Output: 6000.305 500 I find it very handy to use when pulling data from decimal fields in MySQL and putting them into <input> fields. Makes everything cleaner :)

« previous php.notes (#189640) next »