I was wondering if there was any way to round a decimal to the tenths place instead of rounding it to the ones place.
It would make this script I am working on a lot easier.
I was wondering if there was any way to round a decimal to the tenths place instead of rounding it to the ones place.
It would make this script I am working on a lot easier.
You can multiply the value by 10 then round then divide by 10
local RoundedValue = math.round(Value*10)/10
you can simply do this
function roundDeci(n: number, decimal)
return math.round(n * 10 ^ decimal) / (10 ^ decimal)
end
The decimal can be to the nearest tenth, hundredth, and so on and so fourth
I’m assuming as the decimal parameter, I would put 0.1 or a number like that, depending on the place?
If you want a .0 at the end no matter what, then use string formatting.
("%.1f"):format(number) -- number is a variable
What this does is it formats the number to 1 decimal digit, even if there isn’t one.
Adding on to
It would be how many decimal places you want. In your case, it would be 1
.
But if you were to use @daslick 's code then the “decimal” would be how many places you want to round to. 1 would die you tenth’s, 2 would give you hundredths etc.