Skip to content

Commit 75909d1

Browse files
committed
fix: round only if precision is provided in format_pct/2
1 parent 85190f7 commit 75909d1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/algora/shared/util.ex

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,16 @@ defmodule Algora.Util do
106106
end
107107

108108
def format_pct(percentage, opts \\ []) do
109-
precision = opts[:precision] || 0
110-
111-
percentage
112-
|> Decimal.mult(100)
113-
|> Decimal.normalize()
114-
|> Decimal.round(precision)
115-
|> Decimal.to_string(:normal)
116-
|> Kernel.<>("%")
109+
pct = percentage |> Decimal.mult(100) |> Decimal.normalize()
110+
111+
pct =
112+
if opts[:precision] do
113+
Decimal.round(pct, opts[:precision])
114+
else
115+
pct
116+
end
117+
118+
pct |> Decimal.to_string(:normal) |> Kernel.<>("%")
117119
end
118120

119121
def normalize_struct(%Money{} = money) do

0 commit comments

Comments
 (0)