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:
What I tried:
Dividing, rounding up, and more.
Thanks!
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
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.