If I have a variable that has a decimal containing a number like 165.00 or 143.55 ($, duh), what's the best way to check that IF the ending is 00, then strip off the 00 for output?
So:
165.00 would return 165 183.23 would return 183.23 188.00 would return 188
Any ideas?
Thanks,
Mike
Try this:
$dollars = preg_replace ("/.00$/", "", $dollars);
Eden, What is the $ for in "/.00$/"?
It would be faster to use str_replace here instead of preg_replace:
$clean = str_replace( ".00", "", $dirty);
Of course if you aren't doing it alot the performance wouldn't be an issue. 🙂
Jack
It makes sure that the .00 will only get replaced if it is at the end of the string. I guess in this case you don't absolutely NEED to make that stipulation in the regex, because rarely would you see .00 anywhere else but the end of a string, but it works 🙂