2017-07-28 124 views
0

我從MongoDB的在藥劑

{ 
    "id": "123", 
    "name": "foo", 
    "credit": 10000 
} 

拉一些數據由於某種原因,當我得到的信用作爲Float類型與1.0e4其值等於10000科學記數法。
我如何解析它到正常顯示(10000)?

+4

https://stackoverflow.com /問題/ 38734113 /仙丹變頻浮到字符串? – Dogbert

回答

1

要轉換floatinteger您可以使用round/1trunc/1

iex> round(10000.00) 
10000 

iex> trunc(10000.00) 
10000 

要輸出一個浮點數作爲一個整數字符串,可以使用:erlang.float_to_binary/2

iex> :erlang.float_to_binary(10000.00, decimals: 0) 
"10000"