Skip to content

Commit e440662

Browse files
adamzapasnikConnorRigby
authored andcommitted
Use Decimal.from_float/1 instead of Decimal.new/1
1 parent adf5ccc commit e440662

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/sqlite_db_connection/query.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defimpl DBConnection.Query, for: Sqlite.DbConnection.Query do
7575
{result, _} = int |> Integer.to_string |> Float.parse
7676
translate_value({result, type})
7777
end
78-
defp translate_value({float, "decimal"}), do: Decimal.new(float)
78+
defp translate_value({float, "decimal"}), do: Decimal.from_float(float)
7979
defp translate_value({float, "decimal(" <> rest}) do
8080
[precision, scale] =
8181
rest
@@ -85,7 +85,7 @@ defimpl DBConnection.Query, for: Sqlite.DbConnection.Query do
8585

8686
Decimal.with_context(%Decimal.Context{precision: precision, rounding: :down},
8787
fn ->
88-
float |> Float.round(scale) |> Decimal.new |> Decimal.plus
88+
float |> Float.round(scale) |> Decimal.from_float |> Decimal.plus
8989
end)
9090
end
9191

test/repo_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Sqlite.Ecto2.RepoTest do
2424

2525
test "preserves decimal without precision" do
2626
TestRepo.insert!(%MiscTypes{name: "hello", start_time: ~T(09:33:51.130422), cost: 3.1415})
27-
pi_ish = Decimal.new(3.1415)
27+
pi_ish = Decimal.from_float(3.1415)
2828
assert [%MiscTypes{name: "hello", cost: ^pi_ish}] =
2929
TestRepo.all from mt in MiscTypes
3030
end

0 commit comments

Comments
 (0)