Hi, I feel like im doing something wrong here, im trying to round a number with math.round
, but it isnt working, am i doing something wrong, or am i being an idiot? (i feel like i am)
print(math.round(100*10)/10) -- just prints 100
Hi, I feel like im doing something wrong here, im trying to round a number with math.round
, but it isnt working, am i doing something wrong, or am i being an idiot? (i feel like i am)
print(math.round(100*10)/10) -- just prints 100
Uh, what number should it be?, it must round to one decimal place
print(math.round(1.85*10)/10) --> 1.9
print(math.round(1.8274285*10)/10) --> 1.8
Did you accidentally flip the operators? I think this is just confusion.
So what im trying to do turn 100 into 1.0 (or simply 1), but if i have 130, i would want it to be 1.3, but for some reason doing this continues to print 100, i think i can use string.format
for this, i dont remember
Just divide by 100?
print(100/100) --> 1
print(130/100) --> 1.3
if it must always have a decimal place
print(("%0.1f"):format(130/100)) --> 1.3
print(("%0.1f"):format(100/100)) --> 1.0
yeah I just tried that and was about to post it
100*10 is 1,000. Divide 1,000 by 10 and you get 100 as a whole number, so everything seems to be working correctly. Not sure what you want to happen here since you never defined a problem.
math.round will return a whole number that has been either rounded up (if the decimal is 0.5 or greater), or been rounded down (decimal is less than 0.5).
Since the equation you gave above returns a whole number without the need for rounding, there is really no need for math.round().
it’s easy math, you doing (100*10)/10 soo it’s like 1000 /10, and it’s 100
Math.round rounds fractions, like 0.5 and above to 1 and lower to 0
Yeah, then its just a case of me having idiot, thanks
I think you mean Decimals / Floats
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.