2

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 '18 at 9:44
  • Txs. I've just updated the question. – Anibal Nov 14 '18 at 10:03
1

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 agree to our terms of service, privacy policy and cookie policy

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