eksperimental
How to get the ordinary decimal notation of a float
iex> 75000 / 12.5
6.0e3
iex(14)> 75000 / 12.5 |> Float.to_string
"6.0e3"
It is kind of weird that Elixir is formatting such a small number using the scientific notation. Is there a way around to display and/or convert to string the float and get 6000.0 and not 6.0e3?
Cheers
Marked As Solved
outlog
iex> 75000/12.5 |> :erlang.float_to_binary([ decimals: 2])
"6000.00"
or
iex> 75000/12.5 |> :erlang.float_to_binary([:compact, decimals: 2])
"6000.0"
2
Also Liked
alco
The documentation for Float.to_string/1 says
It uses the shortest representation
so I guess that’s why it chooses "6.0e3" over 6000.0, the latter is one character longer.
Take a look at :erlang.float_to_binary/2, here’s how it can be used:
iex(18)> max_precision = 6
6
iex(19)> :erlang.float_to_binary(6000.0, [:compact, decimals: max_precision])
"6000.0"
3
Popular in Questions
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
I want to know absolute current module path. In python i could do that: os.path.abspath(__file__) Does elixir have anything similar?
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
Other popular topics
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
can someone please explain to me how Enum.reduce works with maps
New
I would like to know what is the best IDE for elixir development?
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch.
This project took far...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New








