@@ -141,27 +141,22 @@ defmodule Float do
141
141
142
142
@ doc """
143
143
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).
146
145
147
146
## Examples
148
147
148
+ iex> Float.round(5.5674, 3)
149
+ 5.567
149
150
iex> Float.round(5.5675, 3)
150
151
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)
154
153
-5.567
155
- iex> Float.round(-5.5675, 3, :down )
154
+ iex> Float.round(-5.5675, 3)
156
155
-5.568
157
156
"""
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 )
165
160
end
166
161
167
162
end
0 commit comments