Hi,
I want to know how to get the similar effect like printf(%.7f")?
Here is how I did it:
Float extend [
printStringWithPrecision: anInteger [
<category: 'printing'>
| e value string decPointIndex endPosition tailingZeros
tailingZeroNumber |
e := 1.0 / (10.0 raisedTo: anInteger).
value := self roundTo: e.
string := value printString.
decPointIndex := string findFirst: [ :c | c = $. ].
tailingZeros := ''.
endPosition := decPointIndex + anInteger.
tailingZeroNumber := endPosition - string size.
tailingZeroNumber > 0 ifTrue: [
tailingZeros := String new: tailingZeroNumber withAll:
$0 ].
^(string copyFrom: 1 to: (endPosition min: string size)),
tailingZeros
]
]
But I think there is a better (shorter, elegance) way to do it.
Any suggestions?
lee
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk