struct

PG::Numeric

Inherits Struct / Value / Object

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.

Constructors

new(ndigits : Int16, weight : Int16, sign, dscale : Int16, digits : Array(Int16))
Source

Instance methods

digits

array of numbers from 0-10,000 representing the numeric (not an array of individual digits!)

Source
dscale

number of decimal point digits shown 1.10 is and 1.100 would only differ here

Source
inspect(io : IO)

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)"
Source
nan?

Returns true if the numeric is not a number.

Source
ndigits

size of digits array

Source
neg?

Returns true if the numeric is negative.

Source
sign

positive, negative, or nan

Source
to_big_d

Returns a BigDecimal representation of the numeric. This retains all precision, but requires LibGMP installed.

Source
to_big_r

Returns a BigRational representation of the numeric. This retains all precision, but requires LibGMP installed.

Source
to_f

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. If you require full precision, require the optional big_rational support and use #to_big_r NaN returns 0.0.

Source
to_f64

ditto

Source
to_s(io : IO)

Same as #inspect(io).

Source
weight

location of decimal point in digits array can be negative for small numbers such as 0.0000001

Source