We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
format_pct/2
1 parent 85190f7 commit 75909d1Copy full SHA for 75909d1
lib/algora/shared/util.ex
@@ -106,14 +106,16 @@ defmodule Algora.Util do
106
end
107
108
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.<>("%")
+ pct = percentage |> Decimal.mult(100) |> Decimal.normalize()
+
+ pct =
+ if opts[:precision] do
+ Decimal.round(pct, opts[:precision])
+ else
+ pct
+ end
117
118
+ pct |> Decimal.to_string(:normal) |> Kernel.<>("%")
119
120
121
def normalize_struct(%Money{} = money) do
0 commit comments