Page 1 of 1

"Round" problem.

PostPosted: Wed Dec 30, 2009 9:38 am
by savask
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?

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 1:43 pm
by KarateBrot
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.

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 2:05 pm
by savask
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 } }

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 2:22 pm
by KarateBrot
cool it's my function :D
hmm it didn't happen for me. I used it in this scene:
Rating: rated 6.8
Filesize: 15.11 kB
Comments: 4
Ratings: 5
download

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.

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 2:28 pm
by savask
I tried another round-functions too, and they gave the same result.

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 2:38 pm
by KarateBrot
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?

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 2:43 pm
by savask
No, there is no that problem.

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 3:26 pm
by KarateBrot
Okay. Is your variable that should be rounded an integer or a float number at the beginning when you define it?

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 3:27 pm
by savask
A float number.

Re: "Round" problem.

PostPosted: Wed Dec 30, 2009 3:31 pm
by KarateBrot
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 :thumbup: