Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Truncating Floats in Elixir

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)
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.