Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing a number into a decimal?

I'm trying to figure out how I could change a number into a decimal. For instance, lets use 5243 as an example. I'd like that number to convert to .5243.

I've tried using concatenation but that didn't work.

Thing is, I can't simply predict what the number will be because it's random for every user so I need to be able to change whatever number into a decimal.

1 answer

✓ Accepted answer

Good question! Try this:

function toDecimal(numb, zeroes)
return tonumber("."..string.rep("0", zeroes)..tostring(numb))
end

print(toDecimal(5243, 0))

The code simply concatenates your number with a . in front of it, as well as any amount of zeros you request, and then converts it to a number.

This discussion is preserved as it was. New answers, comments, and votes are closed.