[Haskell-beginners] truncate results depend on strict/lazy

Kim-Ee Yeoh ky3 at atamo.com
Tue Sep 10 00:26:08 CEST 2013


On Tue, Sep 10, 2013 at 5:08 AM, Bryan Vicknair <bryanvick at gmail.com> wrote:

> And all of a sudden, the parsing code doesn't work again!:
>
>   Prelude Data.Text Lib> validateVal $ pack "0.12"
>   Success (Just 11)
>

This might be due to a floating-point roundoff error since 0.12 doesn't
have a finite binary representation.

The function truncate does exactly what it says, so truncate (100 *
0.1199999) evaluates to 11.

Are you sure you don't want "round" instead of "truncate"?

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130910/4beec3c3/attachment.htm>


More information about the Beginners mailing list