Skip to content

Commit

Permalink
Fix a bug where integer values could not be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
sgobotta committed Jan 29, 2024
1 parent 0957611 commit d1f1e9f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
required
step="1"
tabindex="0"
autofocus
phx-debounce={500}
/>
</div>
Expand Down
17 changes: 10 additions & 7 deletions lib/ex_finnhub/api/stock_price.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ defmodule ExFinnhub.StockPrice do
"t" => timestamp
}) do
%__MODULE__{
current: Decimal.from_float(current),
change: Decimal.from_float(change),
percent_change: Decimal.from_float(percent_change),
high: Decimal.from_float(high),
low: Decimal.from_float(low),
open: Decimal.from_float(open),
previous_close: Decimal.from_float(previous_close),
current: parse_number(current),
change: parse_number(change),
percent_change: parse_number(percent_change),
high: parse_number(high),
low: parse_number(low),
open: parse_number(open),
previous_close: parse_number(previous_close),
timestamp: timestamp
}
end

defp parse_number(n) when is_float(n), do: Decimal.from_float(n)
defp parse_number(n), do: Decimal.new(n)
end

0 comments on commit d1f1e9f

Please sign in to comment.