Posted 04 January 2013 - 01:32 AM
Hello everyone.
I am looking for a code that can add thousand separators to a string or a number. I have found this code.
Code:
local s = string.format("%d", math.floor(v))
local pos = string.len(s) % 3
if pos == 0 then pos = 3 end
return string.sub(s, 1, pos)
.. string.gsub(string.sub(s, pos+1), "(…)", ",%1")
.. string.sub(string.format("%.2f", v - math.floor(v)), 2)
end
print(format_thousand(1234567.89))
The problem is that i dont want to have any decimals and my thousand separator should be . instead of ,
can somebody help me please :)/>?
I am looking for a code that can add thousand separators to a string or a number. I have found this code.
Code:
Spoiler
function format_thousand(v)local s = string.format("%d", math.floor(v))
local pos = string.len(s) % 3
if pos == 0 then pos = 3 end
return string.sub(s, 1, pos)
.. string.gsub(string.sub(s, pos+1), "(…)", ",%1")
.. string.sub(string.format("%.2f", v - math.floor(v)), 2)
end
print(format_thousand(1234567.89))
The problem is that i dont want to have any decimals and my thousand separator should be . instead of ,
can somebody help me please :)/>?