Skip to content

Conversation

@Bapham12
Copy link
Member

This module replaces Template:Formatnum functionality with a Lua implementation, providing number formatting based on language and precision.

This module replaces Template:Formatnum functionality with a Lua implementation, providing number formatting based on language and precision.
Removed Luacheck linter step from workflow.
@Bapham12 Bapham12 merged commit 3c417a0 into main Jan 13, 2026
2 checks passed
@Bapham12 Bapham12 deleted the Bapham12-patch-2 branch January 13, 2026 14:33
Comment on lines +108 to +110
if prec > 0 then
local zero = language:formatNum(0)
number = number .. dot .. mw.ustring.rep(zero, prec)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses ASCII dot '.' as decimal separator after language localization, causing incorrect formatting for languages that use different decimal separators (e.g., comma in French/German).

When dot = '.' (set on line 92 when the original number had no decimal point), this appends an ASCII period even though language:formatNum() already localized the number. For example, with French locale:

  • Input: "3", precision: 2
  • Expected: "3,00"
  • Actual: "3.00" (wrong separator)

Fix by extracting the localized decimal separator:

if prec > 0 then
    local zero = language:formatNum(0)
    -- Extract localized decimal separator
    local decimal_sep = language:formatNum(1.5):sub(2, 2)
    if dot ~= '' then
        decimal_sep = '' -- already has separator
    end
    number = number .. decimal_sep .. mw.ustring.rep(zero, prec)
Suggested change
if prec > 0 then
local zero = language:formatNum(0)
number = number .. dot .. mw.ustring.rep(zero, prec)
if prec > 0 then
local zero = language:formatNum(0)
-- Extract localized decimal separator
local decimal_sep = language:formatNum(1.5):sub(2, 2)
if dot ~= '' then
decimal_sep = '' -- already has separator
end
number = number .. decimal_sep .. mw.ustring.rep(zero, prec)

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants