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

#1 2011-09-05 16:41:06

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

How do you get a variable to not be rounded off?

I am trying to make a simulated baseball thing that shows batting average by dividing Hits by At Bats, but the variable simply says "0.2" rather then "0.245" or whatever. Obviously, this is a big problem, as simply "0.2" hardly tells a person anything at all. So, is there any way to get the variable to only round off to 3 decimal places?

Offline

 

#2 2011-09-05 16:42:01

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

Use a list instead.

Offline

 

#3 2011-09-05 16:45:04

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

I guess that works, though it does make everything look unorganized

Offline

 

#4 2011-09-05 16:50:10

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

Another way

Set[Variable] to ( (X) join () )

Edit: Just put the score in the Join block and erase the other side of the join block.

Last edited by laptop97 (2011-09-05 16:51:16)

Offline

 

#5 2011-09-05 16:50:31

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

actually, it still doesnt round to 3 decimal places...

Offline

 

#6 2011-09-05 16:52:25

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

I'll come up with a script hopefully in a little bit.

Offline

 

#7 2011-09-05 16:54:55

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

Okay i did the join thing, now all i need to know is how to round it to 3 places so its not .233333333333333

Offline

 

#8 2011-09-05 16:57:45

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

Re: How do you get a variable to not be rounded off?

Hm... well, you could multiply by a factor of 10 (such as 1000) before dividing. That way it wouldn't try to round it. If you still wanted it to show it as a decimal, you could use the "Join" block to add a decimal point.


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

Offline

 

#9 2011-09-05 17:05:41

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

This will need 3 variables: Score, Actual Score, Index

The score and index should be hidden, the actual score should be show.
When round score is broadcasted the variable score should be set.

When I recieve broadcast [round score]
Set [Actual Score] to ()
Set [Index] to (1)
Repeat Until <(letter (index) of (score)) = (.) >
  Set [Actual Score] to (join (Actual Score)(letter(index) of (score) ) )
  Change [Index] by (1)
{End of Repeat Until}
Repeat (4)
  Set [Actual Score] to (join (Actual Score)(letter(index) of (score) ) )
  Change [Index] by (1)
{End of Repeat}


Sorry if that's hard to understand

Last edited by laptop97 (2011-09-05 17:38:43)

Offline

 

#10 2011-09-05 17:15:47

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

okay i think i got it...let me try it and see if it works

Offline

 

#11 2011-09-05 17:21:44

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

im fairly certain i copied everything correctly, but it is still not rounding...

Offline

 

#12 2011-09-05 17:29:13

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

Upload it and I will probably be able to find the problem.

Offline

 

#13 2011-09-05 17:33:53

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

Thanks for trying to help me though
it is kinda annoying that everything else in the project took 10 minutes to make and this has taken an hour and it still isnt finished -.-

Offline

 

#14 2011-09-05 17:37:40

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

Frogdunker wrote:

Thanks for trying to help me though
it is kinda annoying that everything else in the project took 10 minutes to make and this has taken an hour and it still isnt finished -.-

So, are you going to upload it?

Offline

 

#15 2011-09-05 17:42:31

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

Wait the script is wrong right now, I have to edit it.

Offline

 

#16 2011-09-05 17:47:41

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

oh, i just saw what u said

Offline

 

#17 2011-09-05 17:49:48

laptop97
Scratcher
Registered: 2011-06-27
Posts: 1000+

Re: How do you get a variable to not be rounded off?

I don't know how this will work, the script could be 1/1000 off.

Last edited by laptop97 (2011-09-05 17:50:55)

Offline

 

#18 2011-09-05 17:51:29

Frogdunker
New Scratcher
Registered: 2011-09-05
Posts: 11

Re: How do you get a variable to not be rounded off?

okay i uploaded it....its kinda sloppy but that doesn't matter

Offline

 

#19 2011-09-05 17:54:33

JJROCKER
Scratcher
Registered: 2010-09-06
Posts: 1000+

Re: How do you get a variable to not be rounded off?

I saw the project  big_smile


http://www.blocks.scratchr.org/API.php?action=random&amp;return=image&amp;link1=http://img255.imageshack.us/img255/3491/signature1y.jpg&amp;link2=http://img577.imageshack.us/img577/5272/signature1sx.jpg&amp;link3=http://img4.imageshack.us/img4/8514/signature1et.jpg&amp;link4=http://i.imgur.com/POEpQyZ.png&amp;link5=http://img163.imageshack.us/img163/4640/jjrockerfinal.jpg

Offline

 

#20 2011-09-05 17:59:35

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: How do you get a variable to not be rounded off?

Why not just multiply it by 1000, round it, and divide it by a thousand?


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

Board footer