Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why when I type 0.2 in a NumberValue is shows up as 0.20000000000000989?

local val = script.Parent
local gui = val.Parent
val.Value = .2

gui.Text = val.Value --the text is .200000999 or somehting like that

val is a NumberValue. Can someone help me please? I need the text or value to be exactly .2

5 comments

1

It's due how floating point numbers are stored in the memory. I don't think it's possible to circumvent this unless you want to do some stuff such as storing it as a string then using tonumber() to edit it and back using tostring() to store it again.

1

You can always round to a certain decimal place, if you know what place you need to round to.

1

That can also work.

1

I tried using a StringValue and tonumber() and it worked!

1

If you're just setting the Text of a GuiButton then you don't need to convert the string value into a number.

1 answer

I'm a little bit stumped about this. Try 0.02 if you are aiming for that. (0.02 < 0.2 = 0.20 if you dont' know decimal numbers, which i'm pretty sure you do) or 0.20000000000 (the same amount of 0's that was shown on there)

1 comment

0

please dont listen to me 1 year ago i had no idea what i was saying

This discussion is preserved as it was. New answers, comments, and votes are closed.