5.3 printShowingDecimalPlaces: 2 displays '5.29' insteadof'5.30'
ssastre at seaswork.com
Thu Nov 22 20:39:10 UTC 2007
Ok, don't beat me.. I'm not proud of this but I have to use until I manage
to have something better.
"Answers the scaled decimal with aQuantityOfDigits
of precision represented by the receiver."
ifTrue:[0 asFloat asScaledDecimal: aQuantityOfDigits]
ifFalse:[number asScaledDecimal: aQuantityOfDigits]] value: self asNumber
so my converter can do this depending on it's own configuration (not only
used for money):
"Answers the result of converting aString to a Number or aScaledDecimal."
ifTrue:[aString asScaledDecimal: inputDigits]
Adding the horrible hack:
"Reimplementation - Object 'printing' method."
| aFraction tmpFractionPart |
self < 0 ifTrue: [aStream nextPut: $-].
aFraction := fraction abs.
aStream nextPutAll: aFraction rounded printString.
scale = 0 ifTrue: [^ aStream nextPutAll: 's0'].
aStream nextPut: $..
tmpFractionPart := aFraction fractionPart.
1 to: scale
tmpFractionPart := tmpFractionPart * 10.
(10 <= tmpFractionPart rounded)
ifTrue:[aStream nextPut: $0]
ifFalse:[aStream nextPut: (Character digitValue: tmpFractionPart
tmpFractionPart := tmpFractionPart fractionPart].
I was able to make the values to behave,
De: squeak-dev-bounces at lists.squeakfoundation.org
[mailto:squeak-dev-bounces at lists.squeakfoundation.org] En nombre de tim
Enviado el: Jueves, 22 de Noviembre de 2007 17:10
Para: The general-purpose Squeak developers list
Asunto: Re: 5.3 printShowingDecimalPlaces: 2 displays '5.29' insteadof'5.30'
On 22-Nov-07, at 11:00 AM, Sebastian Sastre wrote:
may be I should clarify that it's only for presentation. The mone value
is stored as anMeasure of it's monetary unit in the Aconcagua framework.
But I'm curious about your answer. Let's supose the user enters in some
input widget with keyboard the '5.30' value. That will end as a Float at
some point. Do you suggest I convert that to a ScaledDecimal? (to
I'm evaluating this:
(5.3 asScaledDecimal: 2)
and also obtainig: ' 5.29s2'
That must surely count as a bug and I'd hazard a guess that it happens
because some code is comparing floats; I've not looked at the code but I've
seen it too many times not to suspect it.
As for your input widget, I'd try to make it give you the string and
directly convert that to a 2dp scaled decimal rather than letting it give
you a float. If there isn't a String>asScaledFloat: type method then I guess
you get to write it :-)
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
All the simple programs have been written, and all the good names taken.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev