# [HELP] How to convert money number?

## Recommended Posts

For example, when i have 1.000.000\$ convert to: 1M\$, or if i have 2.400.000\$ convert to: 2.44M\$. How to make this possible?

can you string.format

41 minutes ago, ZL|LuCaS said:

can you string.format

How?

local moneySuff = {"K", "M", "B", "T", "Q"}

function convertMoney(cMoney)
didConvert = 0
if not cMoney then
return "?"
end
while cMoney / 1000 >= 1 do
cMoney = cMoney / 1000
didConvert = didConvert + 1
end
if didConvert > 0 then
return "\$" .. string.format("%.2f", cMoney) .. moneySuff[didConvert]
else
return "\$" .. cMoney
end
end

Edited by NeXuS™
• 1
• 1
5 minutes ago, NeXuS™ said:

local moneySuff = {"K", "M", "B", "T", "Q"}

function convertMoney(cMoney)
didConvert = 0
if not cMoney then
return "?"
end
while cMoney / 1000 >= 1 do
cMoney = cMoney / 1000
didConvert = didConvert + 1
end
if didConvert > 0 then
return "\$" .. string.format("%.2f", cMoney) .. moneySuff[didConvert]
else
return "\$" .. cMoney
end
end

thank you:D

Very nice

## Create an account

Register a new account