#How do I round to one decimal and whole numbers.

1 messages · Page 1 of 1 (latest)

tepid helm
#

Ive tryed Math.floor and Math.round but they dont do what I need to do.

#

this is why.

heavy basalt
#

can you explain what you want done

tepid helm
#

not to decimal points

heavy basalt
#

ohh

tepid helm
#

math.round(The maths)

heavy basalt
#

okay, what if you do variable = math.round(number*10) / 10

#

try that see if it works

tepid helm
#

is number the calculation?

heavy basalt
#

yeah

#

like number is just whatever you did to get your number in the first place

#

just used it as a placeholder

tepid helm
#

k

heavy basalt
#

lmk if it works

tepid helm
#

it dont work... this is what I did

#

@heavy basalt

heavy basalt
#

or else its going to round your divided value

tepid helm
#

like this?

heavy basalt
#

yes

#

try it now

#

because math.round will return a value then you devide it

tepid helm
#

@heavy basalt uhh

heavy basalt
#

hmm

#

maybe convert it to a string, format it, and then convert back

tepid helm
#

huh

#

how?

#

@heavy basalt

heavy basalt
#

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

tepid helm
#

i just had lunch

#

so we were both away

heavy basalt
#

and to explain how the formatting works the “%.1f” just says keep one decimal the f being a placeholder for numbers

heavy basalt
#

lmk if it works its been a while since I formatted so I could be wrong

tepid helm
#

let you know if what?

tepid helm
heavy basalt
#

if it works

heavy basalt
tepid helm
#

is number a placeholder again?

heavy basalt
#

yes

#

as I dont know how you are getting the value

tepid helm
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

tepid helm
#

ok

#

@heavy basalt it did not work

heavy basalt
#

get any errors?

tepid helm
heavy basalt
#

can I see code?

tepid helm
heavy basalt
#

you have to make the number into one value I believe

tepid helm
#

what number?

heavy basalt
#

the value you are formatting ai dont think you can do operations inside of a .format function

tepid helm
#

oh...

#

how do I do then?

heavy basalt
#

I would make a variable that does the equation then plug the equation into there

tepid helm
#

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

heavy basalt
# tepid helm

oh between "%.1f" and PDS.Value you need a comma and a space

tepid helm
#

ill do tommorow

visual knollBOT
#

studio** You are now Level 8! **studio

bronze sinew
#

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

fair shadow
#

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?

fair shadow
#

anyway try math.round((equation) * 10) / 10