The ~g format

Anthony Shipman als@REDACTED
Wed May 5 12:20:34 CEST 2010


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.


More information about the erlang-questions mailing list