Reputation: 2186
I am pulling some data from mongodb
{
"id": "123",
"name": "foo",
"credit": 10000
}
For some reason when I get the credit as a Float
type with the value of 1.0e4
which is equal to 10000
.
How can i parse it to a regular display (10000) ?
Upvotes: 1
Views: 772
Reputation: 4885
To convert a float
to an integer
you can use round/1
or trunc/1
iex> round(10000.00)
10000
iex> trunc(10000.00)
10000
To output a float as an integer string, you can use :erlang.float_to_binary/2
iex> :erlang.float_to_binary(10000.00, decimals: 0)
"10000"
Upvotes: 2