Today I Learned: Truncating Floats in Elixir

Wednesday August 29, 2018 at 11:35 pm CDT

originally published 4/26/2018 on the Hashrocket TIL blog

To remove everything after the decimal point in a floating-point number, use Kernel.trunc/1.

iex> Kernel.trunc(3.141)
iex> Kernel.trunc(-3.141)

Alternatively, you can simply type trunc

iex> trunc(3.141)

Photo by Jonny Caspari on Unsplash