@@ -141,27 +141,22 @@ defmodule Float do
141141
142142 @ doc """
143143 Rounds a floating point value to an arbitrary number of fractional digits
144- (between 0 and 15) with an optional midpoint rounding mode (:up or :down,
145- defaults to :up).
144+ (between 0 and 15).
146145
147146 ## Examples
148147
148+ iex> Float.round(5.5674, 3)
149+ 5.567
149150 iex> Float.round(5.5675, 3)
150151 5.568
151- iex> Float.round(5.5675, 3, :down)
152- 5.567
153- iex> Float.round(-5.5675, 3)
152+ iex> Float.round(-5.5674, 3)
154153 -5.567
155- iex> Float.round(-5.5675, 3, :down )
154+ iex> Float.round(-5.5675, 3)
156155 -5.568
157156 """
158- @ spec round ( float , integer , atom | nil ) :: float
159- def round ( number , precision , midpoint_rounding // :up ) when is_float ( number ) and is_integer ( precision ) and precision in 0 .. 15 do
160- # Default to :up if anything but :down is provided for midpoint rounding mode
161- case midpoint_rounding do
162- :down -> Kernel . round ( Float . floor ( number * :math . pow ( 10 , precision ) ) ) / :math . pow ( 10 , precision )
163- _ -> Kernel . round ( Float . ceil ( number * :math . pow ( 10 , precision ) ) ) / :math . pow ( 10 , precision )
164- end
157+ @ spec round ( float , integer ) :: float
158+ def round ( number , precision ) when is_float ( number ) and is_integer ( precision ) and precision in 0 .. 15 do
159+ Kernel . round ( number * :math . pow ( 10 , precision ) ) / :math . pow ( 10 , precision )
165160 end
166161
167162end
0 commit comments