|
[
Permalink
| « Hide
]
Eloy Lafuente (stronk7) added a comment - 04/Nov/08 04:07 AM
Getting this... I'll work in a http://moodle.org/stats/index2.php
Closing, as the new format_float() function only allows to localise decimal separator and not thousands separator (that can be comma, point or white space..).
http://moodle.org/stats/index2.php Ciao How wierd, I never saw this bug earlier but actually fixed this page earlier today using number_format() (as well as lots of other formatting issues).
Is it OK if we use commas all the time? :-P I put in a little function that SHOULD work but it's not for some reason ...
moodle_setlocale(); function localisenumber($number) { Yes, localeconv() isn't working fine here (it only returns dec_sep properly defined).
In any case, as we have: $string['decsep'] = '.'; // decimal point separator, for some languages it is ',' in en_utf8/langconfig.php what about to add: $string['thousandsep'] = '.'; // thousands point separator, for some languages it is '.' And then, simply, we use it in private localisenumber() function above? Ciao Gosh that sounds very sensible.
Wow, just discovered that "sensible" in English mean "appropriate" (more or less). In Spanish, literally, it means "dangerous" and I was thinking why were you considering dangerous to add one lang string. LOL.
Oki, I'll add it...ciao Done. Code:
function localisenumber($number, $numdec = 2) { $decimalsep = get_string('decsep'); if (!is_numeric($number)) { return $number; } if ((float)$number == (int)$number) { /// Integer number, no decimals
return (string)number_format($number, 0, $decimalsep, $thousandssep);
} else { /// Float number, apply decimals
return (string)number_format($number, $numdec, $decimalsep, $thousandssep);
} Examples: http://moodle.org/stats/?lang=es I hope you understand this is a major potential problem - mixing , . is going to be a real headache one day. Just printing "correct" formatting is no enough, it should be imho consistent with our parsing of floats when accepting user input. Mixed , . are going to break those automatic conversion hacks for oracle and we will never be able to guess decimal separator!
Also direct use of number_format() is not recommended anymore, we do have format_float() and unformat_float(). I understand /stats is not a core moodle stuff, I just want to make sure we agree on some separators handling for core code
Yup 100% Petr.
IMO unformating/editing shouldn't accept thousand separators at all. But (non-editable) output... that's another story we could talk more. Anyway, this has been exclusively for stats output, using its own function and blah, blah. PS: Oracle? NLS_NUMERIC_CHARACTERS='.,' handles that completely (specifying both the dec and thousands separator). And it's in core since ages. NP (special) there AFAIK. |
|||||||||||||||||||||||||||||||||||||||||||||||||