How exactly does string.format work? I have read the wiki and just don't understand how it works. I am trying to use it to round a decimal down if you need to know ;-;
✓ ANSWER ACCEPTED
How in the world does string.Format Work?
1 answer
✓ Accepted answer
String.format
String.format is essentially has essentially the same functions as printf for the C languages. It essentially, like the name suggests, formats the string with given string patterns.
String patterns include things like %w, %d, and %a
Ex:
local string = "You recieved %d coins %d times!"
local fin = string:format(26,56)
print(fin)--"you recieved 26 coins 56 times!"
Better way to round down
With that said , rounding numbers down to the nearest integer is best done using the math.floor function:
local thing = 124.18321532576
print(math.floor(thing))--124
however, if you want to round down to the nearest multiple of a number n, you should use the modulo operator like such:
local function roundNumDownTo (num,RD)
return num - num%RD
end
print(roundNumDownTo(65,50))--50
2 comments
0
Hey quick question, do you know where I could learn more about all the math. things, for example math.floor Where on the wiki could I learn more about math things like it? If you can put a link, Thanks
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
You should be using math.floor, this will round any given number down
I'll check this and king's answer out thanks :D