[erlang-questions] float number rounded/truncated

Roux Viljoen roux.viljoen@REDACTED
Fri Apr 24 18:09:23 CEST 2009


Gamoto wrote:
> I have the string representation of a float number: "1234.5678"
> I want to transform like this: "12.345678"
> I do: N1 = list_to_float(Number)/100, N2 = float_to_list(N1)
> But the result is:   "1.2345678000....e+001"
>
> My method is bad ;-(
> How to round or trunc a float number in Erlang and to not have a EEE representation ?
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>   
is this what your looking for?

io_lib:format("~.4f",[N1]).

Roux Viljoen

Office: +44 20 7655 0337
Mobile: +44 798 45 44 773
Erlang Training and Consulting Ltd
http://www.erlang-consulting.com/





More information about the erlang-questions mailing list