"Round" problem.

About advanced scenes, and the Thyme scripting language used in Algodoo.

"Round" problem.

Postby savask » Wed Dec 30, 2009 9:38 am

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?
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Postby KarateBrot » Wed Dec 30, 2009 1:43 pm

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.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

Postby savask » Wed Dec 30, 2009 2:05 pm

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 } }
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Postby KarateBrot » Wed Dec 30, 2009 2:22 pm

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.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

Postby savask » Wed Dec 30, 2009 2:28 pm

I tried another round-functions too, and they gave the same result.
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Postby KarateBrot » Wed Dec 30, 2009 2:38 pm

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?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

Postby savask » Wed Dec 30, 2009 2:43 pm

No, there is no that problem.
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Postby KarateBrot » Wed Dec 30, 2009 3:26 pm

Okay. Is your variable that should be rounded an integer or a float number at the beginning when you define it?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: "Round" problem.

Postby savask » Wed Dec 30, 2009 3:27 pm

A float number.
User avatar
savask
 
Posts: 162
Joined: Mon Oct 12, 2009 2:53 pm
Location: Russia, Siberia

Re: "Round" problem.

Postby KarateBrot » Wed Dec 30, 2009 3:31 pm

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:
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest