This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-12-29 21:19:01

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Help with integers

I'm making an OS.  While working on the calculator, I realized that most of the division didn't end.  I've tried rounding, but it just keeps reporting an error.  Is there a way to round an infinite value in Scratch?


http://i49.tinypic.com/rk60py.png

Offline

 

#2 2012-12-29 21:24:49

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: Help with integers

Are you sure your problem isn't a big amount of decimals? You can reduce those by rounding the number to an arbitrary amount of decimals:

set [number v] to (3.14159265)
set [decimals v] to (3)
say ( (round ( (number) * (decimals) )) / (decimals) )
Or eliminate all decimals by just rounding it to the nearest integer:

(round (number))


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#3 2012-12-29 21:42:48

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Help with integers

I've been trying to do:

set [display v] to <round<<(number1)/(number2)>*[1000]>/1000>
It's pretty much the same as what you put, but i'll try what you suggested to see if it works.  Thanks!

Last edited by Programmer_112 (2012-12-29 21:44:02)


http://i49.tinypic.com/rk60py.png

Offline

 

#4 2012-12-29 21:46:32

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Help with integers

Oh, I found the problem.  I was forgetting to set number1 and number 2.  Thanks for helping!


http://i49.tinypic.com/rk60py.png

Offline

 

#5 2012-12-30 20:27:34

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Help with integers

OK, so I have another problem.  Whenever I join a number to another number that ends in zero, the new number replaces 0.  How can I keep the 0?


http://i49.tinypic.com/rk60py.png

Offline

 

#6 2012-12-31 12:26:12

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Help with integers

Help, anyone?


http://i49.tinypic.com/rk60py.png

Offline

 

#7 2012-12-31 13:15:53

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Help with integers

Programmer_112 wrote:

OK, so I have another problem.  Whenever I join a number to another number that ends in zero, the new number replaces 0.  How can I keep the 0?

what? why are you using string operations on numbers? just use math. what is it you're trying to achieve?


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#8 2012-12-31 16:52:29

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Help with integers

I'm trying to make a calculator without using "questions".  I have buttons, and the buttons provide input.  The digits 1-9 all join together fine when i use

<join[][]>
, but if the number that I'm trying to join to ends in 0, the zero is replaced.


http://i49.tinypic.com/rk60py.png

Offline

 

#9 2012-12-31 17:16:17

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Help with integers

so like (join [850] [9]) turns into 859 not 8509? thats weird, it sounds like it might be a bug.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#10 2012-12-31 17:23:34

Programmer_112
Scratcher
Registered: 2012-02-17
Posts: 100+

Re: Help with integers

Oh, I found the problem.  The 0 wasn't using the same system of changing the display because of a different bug with that system, so the old display wasn't being recorded.  Fixed.  Thanks for helping!


http://i49.tinypic.com/rk60py.png

Offline

 

Board footer