'From Squeak3.7beta of ''1 April 2004'' [latest update: #5923] on 26 November 2004 at 10:59:54 am'! "Change Set: PrintShowingDecimalPlacesFix-dtl Date: 26 November 2004 Author: David T. Lewis Adds a range check for Utilities>>floatPrcisionForDecimalPlaces: and a default implementation that works when the parameter is out of range. Implementation note: I used #caseOf:otherwise: to implement this. The result is about 25% slower than the original unchecked method. I got very slightly faster performance by writing it with a bunch of #ifTrue: lines, but I think the caseOf approach is slightly less ugly. All other implementations that I tried (including #at:ifAbsent:, and #on:do) were significantly slower, so I settled on #caseOf:otherwise: for clarity and reasonable speed."! !Utilities class methodsFor: 'miscellaneous' stamp: 'dtl 11/25/2004 22:10'! floatPrecisionForDecimalPlaces: places "Answer the floatPrecision that corresponds to the given number of decimal places" ^ places caseOf: {[0]->[1] . [1]->[0.1] . [2]->[0.01] . [3]->[0.001] . [4]->[0.0001] . [5]->[0.00001] . [6]->[0.000001] . [7]->[0.0000001] . [8]->[0.00000001] . [9]->[0.000000001]} otherwise: [(10.0 raisedTo: places negated) asFloat] " (0 to: 6) collect: [:i | Utilities floatPrecisionForDecimalPlaces: i] (-10 to: 20) collect: [:i | Utilities floatPrecisionForDecimalPlaces: i] "! !