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 ;-;
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!"
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