struct PG::Numeric

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.cr
pg_ext/big_rational.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ndigits : Int16, weight : Int16, sign, dscale : Int16, digits : Array(Int16)) #

[View source]

Instance Method Detail

def digits : Array(Int16) #

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


[View source]
def dscale : Int16 #

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


[View source]
def inspect(io : IO) #
Description copied from struct Struct

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)"

[View source]
def nan? #

Returns true if the numeric is not a number.


[View source]
def ndigits : Int16 #

size of digits array


[View source]
def neg? #

Returns true if the numeric is negative.


[View source]
def sign : Sign #

positive, negative, or nan


[View source]
def to_big_r #

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


[View source]
def to_f : Float64 #

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.


[View source]
def to_f64 : Float64 #

ditto


[View source]
def to_s(io : IO) #
Description copied from struct Struct

Same as #inspect(io).


[View source]
def weight : Int16 #

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


[View source]