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? 

Share this post


Link to post
41 minutes ago, ZL|LuCaS said:

can you string.format

How?

Share this post


Link to post
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™
  • Like 1
  • Thanks 1

Share this post


Link to post
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

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.