#How do I round to one decimal and whole numbers.
1 messages · Page 1 of 1 (latest)
what do you mean math.round doesn’t work? I believe it should
can you explain what you want done
not to decimal points
ohh
math.round(The maths)
okay, what if you do variable = math.round(number*10) / 10
try that see if it works
is number the calculation?
yeah
like number is just whatever you did to get your number in the first place
just used it as a placeholder
k
lmk if it works
you need the /10 outside of the math.round function
or else its going to round your divided value
@heavy basalt uhh
sewrch up how to format in lua
I can give an example
PD.value = string.format(“%.1f”, number)
then after that do PD.value = tonumber(PD.value)
@tepid helm also sorry for late response had to eat dinner
and to explain how the formatting works the “%.1f” just says keep one decimal the f being a placeholder for numbers
alr cool
lmk if it works its been a while since I formatted so I could be wrong
let you know if what?
do i test these?
if it works
yes
is number a placeholder again?
does this go in the same line? @heavy basalt
no, it converts the value from the previous line into a number if you need that, if you dont its not a needed line
get any errors?
can I see code?
you have to make the number into one value I believe
what number?
the value you are formatting ai dont think you can do operations inside of a .format function
I would make a variable that does the equation then plug the equation into there
12:57:54.762 ServerScriptService.Convert:10: Expected identifier when parsing expression, got Unicode character U+201c (did you mean '"'?) - Studio - Convert:10
@heavy basalt
oh between "%.1f" and PDS.Value you need a comma and a space
ill do tommorow
** You are now Level 8! **
If you convert it back to a number the floating point error will show up again
Its a fundamental limit of how computers store numbers
To get around this, you should store the raw PD value elsewhere and update the real PD value with just the string.format operation
it wouldve been funny if nobody told him what a floating point error is but ok
basically the way that computers estimate decimals sometimes leads to very very slight inaccuracies
not a whole lot you can do about that
why not just use an intvalue instead of a numvalue?
anyway try math.round((equation) * 10) / 10