[Seaside] Smalltalk float to currency how to ?
Luc Damas
luc.damas at univ-savoie.fr
Tue Jan 31 15:53:23 CET 2006
Try this ;-)
[ :float :digit | | s |
float = 0
ifTrue: [ s := (String new: digit+1) atAllPut: $0 ]
ifFalse: [ s := (float*(10**digit)) asInteger printString ].
(s copyFrom: 1 to: (s size - digit)) , '.' , (s copyFrom: (s size
-digit+1) to: s size) ]
value: 0.0
value: 2
Dmitry Dorofeev wrote:
> Hi all,
>
> I have Float in form:
> 12.0
> 123.3453
> etc
> and want to format it to two-digits-after-dot.
> Searched through classes but found nothing suitable except
>
> n := 12.6.
> String streamContents: [:s|
> n absPrintOn: s base: 10 digitCount: n asInteger asString size + 2.
> ]
>
> while it works fine for any float like 12.3245
> it does not add zero to float like 12.6 :-(
> I would like to see 12.60
>
> Is there simple way to do it ?
> like fprintf in C/Perl world ?
>
> Thanks.
> -Dmitry.
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
--
-------------------------
Luc Damas
Assistant professor
Condillac, LISTIC, ESIA
University of Savoie
France
http://ontology.univ-savoie.fr/luc.damas
More information about the Seaside
mailing list