Page MenuHomePhabricator

mw.language:formatNum Lua function with noCommafy parameter does not localize decimal point
Open, Needs TriagePublic

Description

mw.language:formatNum Lua function with noCommafy parameter does not localize decimal point. Current results:

  • mw.getLanguage('pl'):formatNum(123456.78) gives "123 456,78" (with comma as decimal point)
  • mw.getLanguage('pl'):formatNum(123456.78, { noCommafy = true }) gives "123456.78" (with period as decimal point)

Expected results

  • mw.getLanguage('pl'):formatNum(123456.78, { noCommafy = true }) giving "123456,78" (with comma as decimal point)

Event Timeline

Jarekt created this task.Feb 28 2018, 7:49 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptFeb 28 2018, 7:49 PM
Anomie added a subscriber: Anomie.

This has nothing to do with Scribunto. It just calls MediaWiki's Language::formatNum(). The bug, if there is one, would be in MediaWiki's Language class.

Arguably the documentation does not say what should happen with noCommafy = true and when passing decimals. But one can also argue that the method is documented to take a float...

Jarekt added a comment.Mar 1 2018, 3:56 PM

Anomie, thanks for clarification. I do not know the implementation details. but you are correct on Polish Wikipedia

  • {{formatnum:987654321.65}} gives "987 654 321,65" (with comma as decimal point)
  • {{formatnum:987654321.65 |NOSEP}} gives "987654321.65" (with period as decimal point)

Expected results

  • {{formatnum:987654321.65 |NOSEP}} should give "987654321,65" (with comma as decimal point)
Aklapper removed a subscriber: Anomie.Oct 16 2020, 5:01 PM

@Jarekt Hi I was looking at this file https://gerrit.wikimedia.org/g/mediawiki/core/+/25c54bf71a491b3ff1057550a3763a388eea932e/languages/Language.php and I found a condition where value of no separator is false[line no: 3297] and I think that in this condition it groups the numbers and adds a comma instead of dot(period). But there is not any condition which handles the case where NOSEP is true so we get an unexpected output. So I think that we should handle this case as well. Please tell me if I am on the right track? Thanks!

if ( !$noSeparators ) {
		...
		}

@Shubham656jain: Please test your changes locally and find out if they fix what they should fix? :)