summaryrefslogtreecommitdiff
path: root/lib/stdlib/test/shell_docs_SUITE_data/unknown_erlang_float_to_list_2_func.txt
blob: 14dbc3763e4c73e43b6f819cb3af19144eb1203e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

  -spec float_to_list(Float, Options) -> string()
                         when
                             Float :: float(),
                             Options :: [Option],
                             Option ::
                                 {decimals, Decimals :: 0..253} |
                                 {scientific, Decimals :: 0..249} |
                                 compact | short.

Since:
  OTP R16B

  Returns a string corresponding to the text representation of 
  Float using fixed decimal point formatting.

  Available options:

   • If option decimals is specified, the returned value
     contains at most Decimals number of digits past the
     decimal point. If the number does not fit in the internal
     static buffer of 256 bytes, the function throws badarg.

   • If option compact is specified, the trailing zeros at the
     end of the list are truncated. This option is only
     meaningful together with option decimals.

   • If option scientific is specified, the float is formatted
     using scientific notation with Decimals digits of
     precision.

   • If option short is specified, the float is formatted with
     the smallest number of digits that still guarantees that F
     =:= list_to_float(float_to_list(F, [short])). When the
     float is inside the range (-2⁵³, 2⁵³), the notation that
     yields the smallest number of characters is used (scientific
     notation or normal decimal notation). Floats outside the
     range (-2⁵³, 2⁵³) are always formatted using scientific
     notation to avoid confusing results when doing arithmetic
     operations.

   • If Options is [], the function behaves as 
     float_to_list/1.

  Examples:

    > float_to_list(7.12, [{decimals, 4}]).
    "7.1200"
    > float_to_list(7.12, [{decimals, 4}, compact]).
    "7.12"
    > float_to_list(7.12, [{scientific, 3}]).
    "7.120e+00"
    > float_to_list(7.12, [short]).
    "7.12"
    > float_to_list(0.1+0.2, [short]).
    "0.30000000000000004"
    > float_to_list(0.1+0.2)
    "3.00000000000000044409e-01"

  In the last example, float_to_list(0.1+0.2) evaluates to 
  "3.00000000000000044409e-01". The reason for this is explained in 
  Representation of Floating Point Numbers.