Truncate a float in Erlang

前端 未结 5 2103
孤独总比滥情好
孤独总比滥情好 2020-12-06 17:35

I am using a function to create a list from a float.

 float_to_list(0.02).

It returns:

\"2.00000000000000000000e-002\"
         


        
5条回答
  •  青春惊慌失措
    2020-12-06 17:59

    Alternatively you could use the function you were already using.

    float_to_list(0.02,[{decimals, 2}]) outputs '0.02'

    Or for Elixir users ;)

    :erlang.float_to_list(5.231,[{:decimals, 2}]) outputs '5.2'

提交回复
热议问题