Editing Module:Utils
From Eco - English Wiki
Your changes will be displayed to readers once an authorized user accepts them. (help)
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 386: | Line 386: | ||
-- Reverse the string of digits. | -- Reverse the string of digits. | ||
-- Append the thousands separator after (before when reversed again) each set of 3 digits. | -- Append the thousands separator after (before when reversed again) each set of 3 digits. | ||
digits = mw.ustring.gsub( | digits = mw.ustring.gsub(mw.ustring.reverse(digits), "(%d%d%d)", mw.ustring.format("%%1%s", thousandsSeparator)) | ||
-- Replace the existing decimal separator with the specified one. | -- Replace the existing decimal separator with the specified one. | ||
fraction = mw.ustring.format("%s%s",decimalPoint, mw.ustring.sub(fraction, 2)) | |||
-- Reverse the string of digits back to the original direction. | -- Reverse the string of digits back to the original direction. | ||
Line 397: | Line 395: | ||
-- Add the optional minus in front and the optional fractional part at the back. | -- Add the optional minus in front and the optional fractional part at the back. | ||
-- Need to remember to escape the thousandsSeparator, it could be "." which would translate to "any character"! | -- Need to remember to escape the thousandsSeparator, it could be "." which would translate to "any character"! | ||
return mw.ustring.format("%s%s%s", minus, mw.ustring.gsub( | return mw.ustring.format("%s%s%s", minus, mw.ustring.gsub(mw.ustring.reverse(digits), mw.ustring.format("^%%s", thousandsSeparator), ""), fraction) | ||
end | end | ||
return p | return p |