Last thing, I'm not sure it's a good idea to deprecate round: round: has been added to overcome the rounding problems of roundTo: If we deprecate round:, then users will fallback to roundTo: and won't get correctly rounded Floats... Thus my original question: why is there a round in python, ruby etc... There must be other applications than just printing (we said financial is one). 2016-11-02 14:40 GMT+01:00 werner kassens <wkassens@libello.com>:
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