[squeak-dev] Float printing

Bert Freudenberg bert at freudenbergs.de
Tue May 15 20:27:21 UTC 2012


Now that we have precise Float printing, using roundTo: to limit the number of printed digits does not work as expected anymore:

	Color red * 0.7
	now ==>  (Color r: 0.7000000000000001 g: 0.0 b: 0.0)
	before ==> (Color r: 0.7 g: 0.0 b: 0.0)

We need an equivalent. There is #printOn:showingDecimalPlaces:, but it always shows the number of digits given, adding trailing zeroes if necessary:

	(Color r: 0.700 g: 0.000 b: 0.000)

What I'd like would be just this, I guess:

	(Color r: 0.7 g: 0 b: 0)

Can someone come up with a #printOn:maxDecimalPlaces: method? Or if some other Smalltalk has an equivalent, use that selector (which hopefully would be shorter)?

- Bert -




More information about the Squeak-dev mailing list