Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How in the world does string.Format Work?

Asked by 6 years ago

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

0
You should be using math.floor, this will round any given number down Ziffixture 6913 — 6y
0
I'll check this and king's answer out thanks :D XX_Scripta 11 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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
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 XX_Scripta 11 — 6y
Ad

Answer this question