[erlang-questions] The ~g format

Robert Virding rvirding@REDACTED
Wed May 5 12:30:24 CEST 2010


The ~g, ~e and ~f formats all print the float in legal Erlang float
syntax which requires the decimal point and digits on both sides of
it. So 23 , 23. , and 23e+1 are not legal floats.

Robert

On 5 May 2010 12:20, Anthony Shipman <als@REDACTED> wrote:
> Why do these differ?
>
> 34> lists:flatten(io_lib:format("~.2g", [23.223466])).
> "2.3e+1"
> 35> lists:flatten(io_lib:format("~.2f", [23.223466])).
> "23.22"
> 36> lists:flatten(io_lib:format("~.3g", [23.223466])).
> "23.2"
>
> The manual says:
>    "If the absolute value of the float does not allow it to be written in the
> f format with the desired number of significant digits, it is also written in
> the e format."
> and that is probably what is happening but I can't match that to the behaviour
> of the code.  In the first case is it trying to avoid writing "23." or
> just "23"?
>
> This is in R12B04
> --
> Anthony Shipman                    Mamas don't let your babies
> als@REDACTED                   grow up to be outsourced.
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list