SylphoidGive feedback
Joined 12 September 2024
update todo with done tasks |
add formatting notes |
||
| Line 43: | Line 43: | ||
| [[Special:Diff/6419|100th edit.]] (Undoing my own edit) | | [[Special:Diff/6419|100th edit.]] (Undoing my own edit) | ||
|} | |} | ||
== Number formatting for thousands separator == | |||
In general Lua, text formatting can be done with: | |||
<syntaxhighlight lang="lua" line> | |||
function Format(amount) | |||
local formatted = amount | |||
while true do | |||
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2') | |||
if (k == 0) then | |||
break | |||
end | |||
end | |||
return formatted | |||
end | |||
</syntaxhighlight> | |||
On Mediawiki installations, formatting should instead be done by: | |||
<syntaxhighlight lang="lua" line> | |||
local lang = mw.language.getContentLanguage() | |||
local function Format(amount) | |||
local formatted = amount | |||
if(type(formatted) ~= "number") then return "<span style=\"color:red;\">Cannot format non-number value.</span>" end | |||
return lang:formatNum(tonumber(formatted)) | |||
end | |||
</syntaxhighlight> | |||