yes Martin, i get that point and i already reacted to it, i occasionally want to calculate something with a rounded float, not print it: apart from my harley i normally use _metric screws which come in decimal steps. <friendly grin> let's end that discussion, we are going around in circles.
werner

On 11/02/2016 02:48 AM, Martin McClure wrote:
Hi Werner,
Thanks for your comments. I posted the analysis because I did the
analysis (and thought some others might want to see it), and I did the
analysis because I wanted to find out whether that answer was right.
Some Smalltalks are pretty bad in similar areas of Float handling.


But aside from all the fine points, if you want a floating-point number
to "look" nice and human-readable,
(x asFraction roundTo:(1/10))asFloat
will work, but I still recommend not rounding the number itself, but
rounding the printing of the number. This is not a Pharo thing, it's an
any-language-with-floats thing. In C you have printf, etc. In Pharo, you
can use for instance:

   1.19 printShowingDecimalPlaces: 1  ==> '1.2'

This makes it easier for someone reading the code to see the intent.

Regards,

-Martin




Reply via email to