-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cafec50
commit f1d550b
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "big" | ||
|
||
module PG | ||
struct Numeric | ||
# Returns a BigDecimal representation of the numeric. This retains all precision. | ||
def to_big_d | ||
return BigDecimal.new("0") if nan? || ndigits == 0 | ||
|
||
# Since BigDecimal allows initialaztion from String, why should one reinvent the wheel? | ||
BigDecimal.new(to_s) | ||
end | ||
end | ||
|
||
class ResultSet | ||
def read(t : BigDecimal.class) | ||
read(PG::Numeric).to_big_d | ||
end | ||
|
||
def read(t : BigDecimal?.class) | ||
read(PG::Numeric?).try &.to_big_d | ||
end | ||
end | ||
end |