[erlang-patches] [patch] new float_to_list/2

Niclas Axelsson <>
Mon Feb 14 14:26:09 CET 2011


On 01/12/2011 06:44 AM, Serge Aleynikov wrote:
> Attached please find a patch that adds a new float_to_list/2 BIF.  The 
> patch was created off of the master branch of 
> https://github.com/erlang/otp.
>
> This BIF solves a problem of float_to_list/1 that doesn't allow 
> specifying the number of digits after the decimal point when 
> formatting floats.
>
>     float_to_list(Float, Options) -> string()
>
>     Float = float()
>     Options = [Option]
>     Option = {precision, Precision::integer()} | compact
>
>     Text representation of a float formatted using given options
>
>     Returns a string which corresponds to the text
>     representation of Float using fixed decimal point formatting.
>         When precision option is specified
>         the returned value will contain at most Precision number of
>         digits past the decimal point.  When compact option is provided
>         the trailing zeros at the end of the list are truncated.
>
>     1> float_to_list(7.12, [{precision, 4}]).
>     "7.1200"
>     2> float_to_list(7.12, [{precision, 4}, compact]).
>     "7.12"
>
> Documentation and test cases are updated to reflect the changes.
>
> Though I included identical support for this new bif in 
> unix/win/vxworks I only tested it on Linux.
>
> Regards,
>
> Serge
>
>
>
> ________________________________________________________________
> erlang-patches (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
Thanks Serge.

Sorry for a late response. Your branch is merged into 'pu'.

Regards,
Niclas Axelsson, Erlang/OTP


More information about the erlang-patches mailing list