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

#1 2010-10-18 20:29:08

yz7hmpm
New Scratcher
Registered: 2010-09-13
Posts: 8

How to get only the integer part of a division?

Hi, i have a problem. Sorry my english is bad.

The problem is.

set a to 12 / 10

I need to return 1 only, and not 1.2.
Similarly:

set b to 18 / 10

I need to return 1 Solal, and not 1.8.

Any idea how to do this?
Thank you very much.

Offline

 

#2 2010-10-18 20:30:17

12three
Scratcher
Registered: 2008-06-12
Posts: 1000+

Re: How to get only the integer part of a division?

Use the round block. It's green, and will round it to nearest... whatever. You get the picture.
-12three-
<round(

Offline

 

#3 2010-10-18 20:40:53

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How to get only the integer part of a division?

12three wrote:

Use the round block. It's green, and will round it to nearest... whatever. You get the picture.
-12three-
<round(

That won't work. Unless I'm mistaken, he wants to just cut the decimal off, not round it. (He wants 1.8 to return 1, not 2, which it would round to.) What you need is a script like this:

http://i51.tinypic.com/2h74dqh.gif


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#4 2010-10-18 20:41:02

yz7hmpm
New Scratcher
Registered: 2010-09-13
Posts: 8

Re: How to get only the integer part of a division?

No really.
The function "round" just do it:

round (1.2) = 1
round (1.8) = 2

I said that i need that back:

1.2 = 1
1.8 = 1

Pls help me...  big_smile

Offline

 

#5 2010-10-18 20:41:54

Jonathanpb
Scratcher
Registered: 2008-07-25
Posts: 1000+

Re: How to get only the integer part of a division?

Use (letter (1) of (a)) - it'll take the first character of the variable "a", which is the number you want.  smile


"Human beings... must have action; and they will make it if they cannot find it.
-Charlotte Brontë

Offline

 

#6 2010-10-18 20:42:33

Harakou
Community Moderator
Registered: 2009-10-11
Posts: 1000+

Re: How to get only the integer part of a division?

yz7hmpm wrote:

No really.
The function "round" just do it:

round (1.2) = 1
round (1.8) = 2

I said that i need that back:

1.2 = 1
1.8 = 1

Pls help me...  big_smile

See my above post.  smile  ^

@jonathanpb: That would work too, unless the number was 10 or more.

Last edited by Harakou (2010-10-18 20:44:52)


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://i.imgur.com/OZn2RD3.png&amp;link2=http://i.imgur.com/duzaGTB.png&amp;link3=http://i.imgur.com/CrDGvvZ.png&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://i.imgur.com/ZKJF8ac.png

Offline

 

#7 2010-10-18 20:58:28

yz7hmpm
New Scratcher
Registered: 2010-09-13
Posts: 8

Re: How to get only the integer part of a division?

This shows the divisors of a number n pairs, and also all displayed digits must be even.

Example n = 60

Must show:
2
4
6
20
60

Try the code you gave me, but turns to negative numbers.

Thank you for your help. I hope answers.

Offline

 

#8 2010-10-18 21:00:19

militarydudes
Scratcher
Registered: 2008-09-12
Posts: 1000+

Re: How to get only the integer part of a division?

Ugg. *shudders* Don't say integer around me. The first time I took a pre-algebra test I got an F.  tongue


__m. .m__ KILROY WAS HERE
        U

Offline

 

#9 2010-10-18 21:03:17

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: How to get only the integer part of a division?

Yep! Just subtract 0.5 and round it.  smile  That way it'll always round down. Good luck!

Offline

 

#10 2010-10-18 21:11:13

yz7hmpm
New Scratcher
Registered: 2010-09-13
Posts: 8

Re: How to get only the integer part of a division?

Hi @Coolstuff.

Dont work with 320 :S

http://yfrog.com/jnsssssbjj

Its the image of my work in scratch.

Ty for advance.

Offline

 

#11 2010-10-18 21:20:12

bbbeb
Scratcher
Registered: 2009-06-11
Posts: 1000+

Re: How to get only the integer part of a division?

set a to (round ((12/10)-1/2))

that will get 1.

I guarantee that works.
<set{ a }to( <round( (((( 12 </>10  ))  <-> 0.5 )) )


Back in my day.... there were no laws that censored the internet... now, there are.... nah.

Offline

 

#12 2010-10-18 21:32:31

yz7hmpm
New Scratcher
Registered: 2010-09-13
Posts: 8

Re: How to get only the integer part of a division?

Ty so much. Now work. Ty to @Harakou and @bbbeb.

Bye.

Offline

 

#13 2010-10-19 06:29:04

12three
Scratcher
Registered: 2008-06-12
Posts: 1000+

Re: How to get only the integer part of a division?

Harakou wrote:

12three wrote:

Use the round block. It's green, and will round it to nearest... whatever. You get the picture.
-12three-
<round(

That won't work. Unless I'm mistaken, he wants to just cut the decimal off, not round it. (He wants 1.8 to return 1, not 2, which it would round to.) What you need is a script like this:

http://i51.tinypic.com/2h74dqh.gif

Whoops, didn't quite understand. This method should work.
-12three-

Offline

 

#14 2010-10-19 07:14:10

mathematics
Scratcher
Registered: 2009-03-01
Posts: 1000+

Re: How to get only the integer part of a division?

Just use this:

[blocks]<round( (( something <-> 0.5 ))[/blocks]

Offline

 

#15 2010-10-20 00:18:00

wei2912
Scratcher
Registered: 2010-05-09
Posts: 100+

Re: How to get only the integer part of a division?

Examples:

Code:

set left over to 12 mod 10

Left over will become 2

Code:

set Answer to 12 - Left over / 10

Done. Hope this helped you. This works for everything.

Last edited by wei2912 (2010-10-20 00:18:48)


Waiting for Scratch 2.0...

Offline

 

Board footer