[Seaside] Smalltalk float to currency how to ?

Florian Minjat florian.minjat at emn.fr
Wed Feb 1 10:59:54 CET 2006


I had the same need, so I added this message in Float :
----------
roundedTo: precision
	"Answer the float truncated at precision decimal"
	(self rounded = self)
	ifTrue: [ ^ self rounded ]
	ifFalse: [ ^ (((self * (10 raisedTo: precision)) rounded) / (10 
raisedTo: precision)) asFloat ]
----------
It's working fine for me.

Florian

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
> 


More information about the Seaside mailing list