当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


erlang float_to_binary(Float, Options)用法及代码示例


float_to_binary(Float, Options) -> binary()
OTP R16B
类型:
Float = float()
Options = [Option]
Option = 
    {decimals, Decimals :: 0..253} |
    {scientific, Decimals :: 0..249} |
    compact | short

返回对应于文本表示的二进制Float使用固定小数点格式。Options其行为方式与 float_to_list/2.例子:

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

相关用法


注:本文由纯净天空筛选整理自erlang.org大神的英文原创作品 float_to_binary(Float, Options) -> binary()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。