當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。