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

Gleb Peregud <>
Wed Jan 12 15:23:29 CET 2011

Some time ago I've submitted similar but simpler patch. It was a
float_to_list/2 with a second parameter being an integer specifying
precision. For me it was important to generate A LOT of floats as
strings as fast as possible with specified precision. Serge's version
has an overhead of inspecting proplist of the second parameter. So I
was wondering about introducing two versions of this function: with a
proplist as a second parameter and with a number as a second
parameter. Alternatively proplist version can be factored out into

Just my 0.2 cents

On Wed, Jan 12, 2011 at 15:10, Serge Aleynikov <> wrote:
> The reason I called it precision was to be consistent with the naming
> convention of the printf function.  Below is the extract from "man 3
> printf", which refers to the digits after the decimal point as "precision":
>       f, F   The  double  argument is rounded and converted to decimal
>              notation in the style [-]ddd.ddd, where the number of
>              digits after the decimal-point character is equal to the
>              precision specification.  If the precision is missing,
>              it  is taken as 6; if the precision is explicitly zero,
>              no decimal-point character appears.  If a decimal point
>              appears, at least one digit appears before it.
> I don't have a very strong preference for calling it precision or scale, but
> I do have a strong preference for including this patch in the distribution,
> because the default behavior of float_to_list/1 hard-coded in C is
> deficient.
> On 1/12/2011 4:58 AM, nox wrote:
>> Il should be called "scale", shouldn't it?
>> Le 12 janv. 2011 à 10:26, Pierpaolo Bernardi<>  a écrit
>> :
>>> On Wed, Jan 12, 2011 at 06:44, 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.
>>> I think the option is misnamed.
>>> In the usual terminology, 'precision' is the total number of
>>> significative digits, not only the ones past the decimal point.
>>> Cheers
>>> P.
>>> ________________________________________________________________
>>> erlang-questions (at) erlang.org mailing list.
>>> See http://www.erlang.org/faq.html
>>> To unsubscribe; mailto:
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:

More information about the erlang-questions mailing list