How to make a 00000 currency value show?

Hey, I want to make a simple currency UI but with a twist that I guess requires math.
I want to make something like this:
Imagine you have a normal currency interface, and it looks like this:
1200$,
now what I want to do, would look like this:
00001200$.
Now the problem is, what maths formula do I use to convert the 1200 to a 1200 with 4 zero’s infront?
Here’s a better image of what I want to do:
s

What I tried:
Dividing, rounding up, and more.
Thanks!

Just so you know, I want the marths formula to work with any number. For example 4, 10240 or 3959.

use this:

local cash = --cash
local textlabel = --textlabel to put the text in
cash.Changed:Connect(function()
local length = string.len(tostring(cash.Value))
local newString = ""
local times = 0
repeat
newString ..= "0"
until times == 8 - length
newString ..= cash.Value
textlabel.Text = newString
end)

Basically, what I did was use string.len and tostring to get the length of cash. Then, I repeated the amount of 0’s needed and added the cash onto it.

You’re not going to use a math formula, instead, you’re going to write a conversion function. number -> string.

local pattern = "%08d" -- Add maximum of 8 zeros on left side of integer.
local function numberToCurrency(value)
    return string.format(pattern, tostring(value))
end

Patterns are cool.

1 Like

Wow, I totally did not know that existed! A string format?

You can also use string.format

(Edit) looks like utrain beat me to it.

print(string.format("%08i", 4))
print(string.format("%08i", 10240))
print(string.format("%08i", 3959))
1 Like

We always learn something new every day, here is the documentation for that function: MUSHclient documentation: contents

I recommend you read the manual about string manipulation in general here: Programming in Lua : 20

At this point I do not know which solution would be more efficient. Although Kaiden’s solution would take loops which is less efficient, and I love your take on the solution.