monkeypaw201 Posted August 31, 2008 Share Posted August 31, 2008 i have this number: -006.270000 and i need it to become: -6.270000 the number of 0's may vary, there also may or maynot be the - sign.. any suggestions? Link to comment https://forums.phpfreaks.com/topic/122047-removing-0s-in-front-of-the-decimal/ Share on other sites More sharing options...
phpcodec Posted August 31, 2008 Share Posted August 31, 2008 I'm not quite sure, but this may work $number = '006.270000'; $new_number = explode(".",$number); $new_number2 = str_replace("0","",$new_number[0]); $new_number = $new_number2.$new_number[1]; echo $new_number; Link to comment https://forums.phpfreaks.com/topic/122047-removing-0s-in-front-of-the-decimal/#findComment-630039 Share on other sites More sharing options...
monkeypaw201 Posted August 31, 2008 Author Share Posted August 31, 2008 ok, with a bit of modding that should work thanks! Link to comment https://forums.phpfreaks.com/topic/122047-removing-0s-in-front-of-the-decimal/#findComment-630045 Share on other sites More sharing options...
Barand Posted August 31, 2008 Share Posted August 31, 2008 <?php $number = '006.270000'; printf ('%0.6f', $number); // --> 6.270000 ?> Link to comment https://forums.phpfreaks.com/topic/122047-removing-0s-in-front-of-the-decimal/#findComment-630050 Share on other sites More sharing options...
Barand Posted August 31, 2008 Share Posted August 31, 2008 or <?php $number = '-006.270000'; echo number_format ($number, 6); ?> Link to comment https://forums.phpfreaks.com/topic/122047-removing-0s-in-front-of-the-decimal/#findComment-630051 Share on other sites More sharing options...
.josh Posted August 31, 2008 Share Posted August 31, 2008 another random one which may or may not suit your needs: $b = "-" . (substr($b,-); eh...i didn't read that bit about there maybe not being a - sign nvm. Link to comment https://forums.phpfreaks.com/topic/122047-removing-0s-in-front-of-the-decimal/#findComment-630058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.