struct PG::Numeric
- PG::Numeric
- Struct
- Value
- Object
Overview
The Postgres numeric type has arbitrary precision, and can be NaN, "not a number".
The default version of Numeric in this driver only has #to_f which
provides approximate conversion. To get true arbitrary precision, there is
an optional extension pg_ext/big_rational, however LibGMP must be
installed.
Defined in:
pg/numeric.crpg_ext/big_rational.cr
Constructors
Instance Method Summary
-
#digits : Array(Int16)
array of numbers from 0-10,000 representing the numeric (not an array of individual digits!)
-
#dscale : Int16
number of decimal point digits shown 1.10 is and 1.100 would only differ here
-
#inspect(io : IO)
Appends this struct's name and instance variables names and values to the given IO.
-
#nan?
Returns
trueif the numeric is not a number. -
#ndigits : Int16
size of digits array
-
#neg?
Returns
trueif the numeric is negative. -
#sign : Sign
positive, negative, or nan
-
#to_big_r
Returns a BigRational representation of the numeric.
-
#to_f : Float64
The approximate representation of the numeric as a 64-bit float.
-
#to_f64 : Float64
ditto
-
#to_s(io : IO)
Same as
#inspect(io). -
#weight : Int16
location of decimal point in digits array can be negative for small numbers such as 0.0000001
Constructor Detail
Instance Method Detail
array of numbers from 0-10,000 representing the numeric (not an array of individual digits!)
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
Returns a BigRational representation of the numeric. This retains all precision, but requires LibGMP installed.
The approximate representation of the numeric as a 64-bit float.
Very small and very large values may be inaccurate and precision will be
lost.
NaN returns 0.0.
location of decimal point in digits array can be negative for small numbers such as 0.0000001