Logo

Programming-Idioms

History of Idiom 81 > diff from v50 to v51

Edit summary for version 51 by programming-idioms.org:
[Elixir] Dead link: play.elixirbyexample.com has been down for a while

Version 50

2019-09-27, 14:29:26

Version 51

2019-10-14, 12:27:32

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Idiom #81 Round floating point number to integer

Declare integer y and initialize it with the rounded value of floating point number x .
Ties (when the fractional part of x is exactly .5) must be rounded up (to positive infinity).

Code
y = Float.round x
Code
y = Float.round x
Comments bubble
Note that negative ties are not rounded up.
Comments bubble
Note that negative ties are not rounded up.
Doc URL
http://elixir-lang.org/docs/stable/elixir/Float.html#round/2
Doc URL
http://elixir-lang.org/docs/stable/elixir/Float.html#round/2
Demo URL
http://play.elixirbyexample.com/s/ca0c80f667