Just curious...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Just curious...

horrido
In the Playground, if I type in

0.1s

and then "Print it", I get the following output:

0.1s1

What does the s1 stand for? Why doesn't it simply print s?

Reply | Threaded
Open this post in threaded view
|

Re: Just curious...

Esteban A. Maringolo
The number after the s is the scale of the ScaledDecimal.

E.g. If you write 0.1s3 it means you instantiate a ScaledDecimal that is 0.001

So it sems that printOn: in ScaledDecimal is being "explicit" as it
prints 1 when other dialects don't.

Regards,

Esteban A. Maringolo


On Thu, Jan 30, 2020 at 2:07 PM Richard Kenneth Eng
<[hidden email]> wrote:

>
> In the Playground, if I type in
>
> 0.1s
>
> and then "Print it", I get the following output:
>
> 0.1s1
>
> What does the s1 stand for? Why doesn't it simply print s?
>

Reply | Threaded
Open this post in threaded view
|

Re: Just curious...

Esteban A. Maringolo
Errata:

> E.g. If you write 0.1s3 it means you instantiate a ScaledDecimal that is 0.001

I meant: 0.1s3 = 0.100

Esteban A. Maringolo


On Thu, Jan 30, 2020 at 2:28 PM Esteban Maringolo <[hidden email]> wrote:

>
> The number after the s is the scale of the ScaledDecimal.
>
> E.g. If you write 0.1s3 it means you instantiate a ScaledDecimal that is 0.001
>
> So it sems that printOn: in ScaledDecimal is being "explicit" as it
> prints 1 when other dialects don't.
>
> Regards,
>
> Esteban A. Maringolo
>
>
> On Thu, Jan 30, 2020 at 2:07 PM Richard Kenneth Eng
> <[hidden email]> wrote:
> >
> > In the Playground, if I type in
> >
> > 0.1s
> >
> > and then "Print it", I get the following output:
> >
> > 0.1s1
> >
> > What does the s1 stand for? Why doesn't it simply print s?
> >

Reply | Threaded
Open this post in threaded view
|

Re: Just curious...

vince
In reply to this post by horrido

Hi Richard

 

For “Print it” representations of objects, you can browser the #printOn: method of the class of that object.

 

For ScaledDecimal, it is:

 

 

printOn: aStream

     "Append an approximated representation of the receiver on aStream.

     Use prescribed number of digits after decimal point (the scale) using a rounding operation if not exact"

    

     self printOn: aStream showingDecimalPlaces: scale.

 

     "Append a scale specification so that the number can be recognized as a ScaledDecimal"

     aStream nextPut: $s; print: scale.

 

Vince