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

#1 2009-09-12 13:37:28

phreddo
Scratcher
Registered: 2009-09-12
Posts: 4

Controlling how numbers are formatted

Hi!

I have written a basic temperature conversion program, but I'm having problems with the way the output is format.

If I do: "say x" then I get the output looks like it is formatted for 2 decimal places

What I'd really like to do is have my little guy say "the answer is x"

If, however i use the join block, then the answer now is accurate to 10 decimal places, which makes the output look a bit ugly.

Is there a way to control this? I only see the "round" block, but I need a bit more precision than that.

tia!

Offline

 

#2 2009-09-12 13:48:05

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: Controlling how numbers are formatted

Code:

[say (join [The answer is ] ((round ((x) * (100))) / (100))]

The multiplying, rounding, then dividing is the only method I have found of rounding to the nearest number.

Hope that helps...

Last edited by The-Whiz (2009-09-12 13:50:22)

Offline

 

#3 2009-09-12 14:30:54

phreddo
Scratcher
Registered: 2009-09-12
Posts: 4

Re: Controlling how numbers are formatted

Fantastic! Thanks so much!

Offline

 

#4 2009-09-12 14:51:06

DarthPickley
Scratcher
Registered: 2008-06-13
Posts: 100+

Re: Controlling how numbers are formatted

The-Whiz wrote:

Code:

[say (join [The answer is ] ((round ((x) * (100))) / (100))]

The multiplying, rounding, then dividing is the only method I have found of rounding to the nearest number.

Hope that helps...

I used that approach very recently... for my updated version of the Geometry Construction Tools.

Offline

 

Board footer