Trailing Zeros and Decimals
Moderator: General Moderators
- ILoveJackDaniels
- Forum Commoner
- Posts: 43
- Joined: Mon May 20, 2002 8:18 am
- Location: Brighton, UK
Trailing Zeros and Decimals
I really need to remove the trailing zeroes from a set of usersubmitable numbers. The problem is that the user may submit numbers with 0, 1 or 2 decimal places. If they only use one decimal place, the number looks like 10.20 - and I need to strip out that trailing zero. I can't do it with number_format, because I don't know how many trailing zeros I need to split out of each number. Can anyone help?
- Fredix
- Forum Contributor
- Posts: 101
- Joined: Fri Jul 18, 2003 2:16 pm
- Location: Wehr (Eifel) Germany
- Contact:
you could search the number for a dot " . "
if the number is 10 you don't do anything
but if there is a dot - the number could be 18.900
you start a loop that reads from right to left and looks whether the number is == 0 if so you delete it and do this until the number you are looking at is != 0
hope i helped
if the number is 10 you don't do anything
but if there is a dot - the number could be 18.900
you start a loop that reads from right to left and looks whether the number is == 0 if so you delete it and do this until the number you are looking at is != 0
hope i helped
- ILoveJackDaniels
- Forum Commoner
- Posts: 43
- Joined: Mon May 20, 2002 8:18 am
- Location: Brighton, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try this:
Mac
Code: Select all
$test = '12.3400000';
echo $test.'<br />';
$stripped_zeros = (float)$test;
echo $stripped_zeros;