I'm wondering if there is J-API way to parse and format numbers (like JDate).

When you convert decimal numbers into different locales, the user can enter numbers in this way "1.234.567,891" and Joomla must save it to SQL as "1234567.891" and finally the number must be shown back as "1.234.567,891". Of course, most users only enter "1234567,891", and the conversion to SQL must work similarly.

Something like numfmt_parse and numfmt_format.

$fmt = numfmt_create( 'de_DE', NumberFormatter::DECIMAL );
$num = "1.234.567,891";
echo numfmt_parse($fmt, $num)."\n";
echo numfmt_parse($fmt, $num, NumberFormatter::TYPE_INT32)."\n";

Is there any better way to convert floats according to the user locale?

  • When you convert decimal numbers into different locales, the user can enter numbers in this way "1.234.567,891" and Joomla must save it to SQL as "1234567.891" and finally the number must be shown back as "1.234.567,891". Of course, most users only enter "1234567,891", and the conversion to SQL must work similarly. – Anibal Nov 14 at 9:44
  • Txs. I've just updated the question. – Anibal Nov 14 at 10:03

There is JHtmlNumber class but it only has a method for converting bytes.

Because Joomla! does not use INTL extension, formatting there is done using simple number_format() with language strings (THOUSANDS_SEPARATOR and DECIMALS_SEPARATOR) acting as separators. So formatting would depend on user's language.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.