[Haskell-cafe] Problem with percentage function?

Karl Voelker karl at karlv.net
Sun Apr 20 21:21:45 UTC 2014

On Sun, Apr 20, 2014, at 02:12 PM, Chapman, Anthony Sergio wrote:
> I would it to round to 2 decimal places no matter what the size of the
> input is

> The problem is that what I actually get is 22.220000000000002

The Double type cannot represent all values exactly, which produces this
behavior. [1]

If you just want to round the number for display purposes, you should
probably round it as part of the conversion to text.

Otherwise, there are a lot of other numeric representations, but the
right one would depend on your application.


1: http://en.wikipedia.org/wiki/Double_precision_floating-point_format

More information about the Haskell-Cafe mailing list