On Wed, Feb 4, 2015 at 7:22 PM, Chuck Hipschman <ckhipsch...@gmail.com> wrote:
> 7 / 8.0 roundTo 0.01 = 0.88 Aha! Thanks! > > But: > > 100 * (1.05 raisedTo: 10) roundTo: 0.01 162.89000000000001 > > "162.88946267774418" "unrounded" > 100 * (1.05 raisedTo: 15) roundTo: 0.01 207.89000000000001 > > "207.8928179411367" "unrounded" > Bug, or me again :-) > > If you debug into #roundTo: you'll see its implementation is simple arithmetic, subject to the vagaries of float resolution. Float(Number)>>roundTo: ^(self / quantum) rounded * quantum Now are you wanting something nicely formatted for display, or are you rounding for some mathematic purpose? Perhaps instead you are wanting... 100 * (1.05 raisedTo: 10) printShowingDecimalPlaces: 2 " --> 162.89 " 0.105 printShowingDecimalPlaces: 2 " --> 0.10 " 0.115 printShowingDecimalPlaces: 2 " --> 0.12 " btw, I only found these today, looking in the printing protocol of Number and Float. cheers -ben
_______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners