"Round" problem.

"Round" problem.

Sometimes when I'm using round function, it gives me 0.60000002 or 0.30000001 instead of 0.6 and 0.3.
Is there a way to hide this useless digits?

Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Do you use the round function from the some extra math functions thread or do you just cut the last decimal places?
This sometimes happens if you just cut them but I don't know why. It's how Phun and Algodoo are dealing with digits.

KarateBrot

Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

I used this round function:
Code: Select all
`Scene.my.round = (x, digits) => { ( x*10^(digits + 1) - math.mod(x*10^(digits + 1), 1) ) >= ( (x*10^digits - math.mod(x*10^digits, 1) ) * 10 + 5 ) ? { ( (x*10^digits - math.mod(x*10^digits, 1)) + 1 ) / 10^digits } : { (x*10^digits - math.mod(x*10^digits, 1)) / 10^digits } }`

Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

cool it's my function
hmm it didn't happen for me. I used it in this scene:
Rating:
Filesize: 15.11 kB
Ratings: 5

With the number of digits I used it worked. I'll take a deeper look into it later. You can also try the function in the "some extra math functions" thread. Maybe it works better but I don't know. I'll definitely improve my function.

KarateBrot

Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

I tried another round-functions too, and they gave the same result.

Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Ok, then maybe this is caused by your scene. I can try to customize the function so that it works for you, too.
But one more question: If you open up my scene which I posted above and then if you make the displays only display one decimal place (look into the scripting menu of the displays), does it work or do you get the same problem?

KarateBrot

Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

No, there is no that problem.

Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Okay. Is your variable that should be rounded an integer or a float number at the beginning when you define it?

KarateBrot

Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

A float number.

Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Hmm I didn't expect that. I once had problems with this too. I just had an improper starting value (but it was float too). After I used 0.5 at the beginning it rounded correct. I'll take a look at it tomorrow. I'm busy right now, sorry.

Edit:
I didn't figure it out yet. I'm away for a week now but I'll think about this problem

KarateBrot

Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany