which version of Pharo/VM are you using?
Cause in my latest 1.4 and latest 2.0 this seems to work...

String streamContents: [ :s| -0.55s2 printOn: s ] "yields the expected 
'-0.55s2'"

I remember Mariano once had a strange integer issue since he accidentally used 
once of 
is own compiled VMs which wasn't working as expected.


best
cami

On 2012-08-09, at 23:53, Guy <[email protected]> wrote:

> Team Pharo,
> The printOn: method in ScaledDecimal returns a positive number string where 
> the number is >-1 and < 0. For example -0.55s2 returns a string '0.55s2'. 
> 
> I have made my own correction. 
> 
> This may help the one other person who is using ScaledDecimal as a proxy for 
> Currency but I have no idea what to do with this astounding discovery nor 
> whether it will help anyone nor indeed if it is very tidy code.
> 
> Thanks
> 
> Guy Bloomfield
> 
> The current method starts with the string for the integer part 0 and then the 
> absolute value of the fraction:
> 
> 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"
>       
>       | fractionPart |
>       scale = 0
>               ifTrue: [self rounded printOn: aStream]
>               ifFalse: [self integerPart printOn: aStream.
>                       aStream nextPut: $..
>                       fractionPart := (self abs fractionPart * (10 
> raisedToInteger: scale)) rounded.
>                       .....
> 
> My correction:
> 
> 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"
>       
>       | fractionPart |
>       
>       self < 0 ifTrue: [ aStream nextPut: $- ].
>       
>       scale = 0
>               ifTrue: [self rounded printOn: aStream]
>               ifFalse: [self abs integerPart printOn: aStream.
>                       aStream nextPut: $..
>                       fractionPart := (self abs fractionPart * (10 
> raisedToInteger: scale)) rounded.
>                       .....
> 
> 


Reply via email to