# How to round decimals

For whatever reason my number ends up gaining a random 0.0000001 and it makes the UI look horrible, any way to round to the nearest tenth (0.1) ?

Put in an expression Math.round(A*10)/10

2 Likes

I can’t deal with this right now, the positive works, but when it adds a negative, it goes to zero but keeps the old save. None of that made sense, but i’m about to implode.

Computers use stuff to do math as quickly as possible, resulting in stuff like this. Do what I said: Math.round(A*10)/10

1 Like

That’s what I have… Except I used /100 because I wanted one decimal point.

Where’s the Math.round? Adding /100 will ruin it as well.

What is a math.round, isn’t that the expression?, Multiplies by 10 and divides by 100 going from 1 to 0.1

PUT EXACTLY WHAT I TYPE IN THE EXPRESSION…
Math.round(A*10)/10

How do you think people do exponential stuff? Math.pow. They are functions.

Still doesn’t tell me why it randomly adds a whole 1, it shows up nowhere in the code, yet happens everytime.
If I scale it up then every down press will subtract 1.1, works the other way too.
And then sometimes it’ll just stop allowing me to change the number, when it’s not even at the limit.

This is why.

You’d be surprised to know that computers suck at math. They go as fast as possible, resulting in stuff such as 1 + 2 = 3.0000000000000000000004

alright so, any way to fix it?

How many times do I have to say this.

Math.round rounds the number, meaning 10.32 rounds to 10. If you do Math.round(A*10) it does “Math.round(103.2) = 103”, then dividing by 10 gives you 10.3

1 Like

.00001 to .1 is technically rounding up, so if you just want the first decimal place, try this:
Math.ceil(A*10)/10

ceil means to only round up,
floor means to only round down,
round means to round closest value.

2 Likes