How to convert dot to comma in a number

In the Portuguese language, decimal separators are inverted: 12.345 = 12,345

I tried to use this to convert:
print(string.gsub("12.345", ".", ","))

But I got:
,,,,,, 6

How to convert a dot to a comma in a simple way (string.gsub)?

That’s because the . character class means to match all characters.
You could match . literally by using the escape character % so if you want to replace literal . with a comma then use "%." as a replacement string.

(I recommend you use an i18n library for this if possible as this will become non-trivial to implement)

1 Like

http://lua-users.org/wiki/LuaLocales

Slightly off-topic but vanilla Lua’s locale can be set to accomodate numbers in that format.

1 Like