From: Don S. <do...@se...> - 2003-02-24 18:24:57
|
In my db table I have a "price" field of type "numeric(16,2)". It works great unless someone tries to use a comma for a thousands separator, like "125,000". mysql saves it as "125". I believe that mysql is treating both the "." and "," characters as decimal places. I'm looking through php's number_format option but I can't get it to smartly remove the thousands separator. I don't just want to say "remove the comma" because in some locale's the comma is the decimal point. I saw this function: function number_format_locale ($num, $decimals = null) { $locale = localeconv(); if(!isset($decimals)) $decimals = $locale['frac_digits']; return number_format($num, $decimals, $locale['decimal_point'], $locale['thousands_sep']); } But on my machine all the $locale vars are empty. Does anyone know of a reliable means to get rid of the thousands separators? My last resort would be to look for the last comma or period, and assume that is the decimal point. Then strip out all others. Although there could be the case that the user doesn't need the decimals and doesn't specify the decimal point. But that should be easy enough. Don. |