[erlang-questions] In Erlang , {1.1*1.1.} show me the answer is 1.2100000000000002, why?

Loïc Hoguin essen@REDACTED
Sun Oct 26 10:02:39 CET 2014


Floats are an inaccurate number format.

See http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

Decimal32/decimal64 are the accurate equivalent, though quite new and as 
of now rarely found natively in programming languages.

On 10/26/2014 08:24 AM, 张栋 wrote:
> Hello the maillist member:
> I am  new in Erlang,Please Help me.
>
> When I try some multiplication, I got the someunexpectedanswerabout the
> following expression.
>
> Please help!
>
> List:
>
> 23> [1.1*1.1,1.1*1.2,1.1*1.3,1.1*1.4,1.1*1.5].
> [1.2100000000000002,1.32,1.4300000000000002,1.54,
>   1.6500000000000001]
>
> 24> [1.2*1.2,1.2*1.3,1.2*1.4,1.2*1.5,1.2*1.6].
> [1.44,1.56,1.68,1.7999999999999998,1.92]
>
> Thank you for your time.
>
> Eric D. Zhang In China.
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>

-- 
Loïc Hoguin
http://ninenines.eu



More information about the erlang-questions mailing list