Module Dbi.Decimal


module Decimal: sig .. end


Module to handle arbitrary precision decimal numbers.

A decimal number is a number of the form n 10^e with n, e integers. It characterized by its precision (i.e., its total number of digits) and its scale. For example, 103.12 has precision 5 (or more) and scale 2. In this implementation, the precision is taken as +infinity and the scale adapts dynamically.

type t 
Abstract type for decimal numbers
val to_string : t -> string
to_string n returns a string representation of the decimal number n.
val to_float : t -> float
to_float n returns the closer float to n.
val of_string : ?scale:int -> string -> t
of_string ?scale s returns the decimal number represented by the string s. If the option scale is not set, the scale will be the one of the string representation. If scale is given, it will be enforced, possibly truncating the number.
Raises Invalid_argument if scale < 0.
val of_int : ?scale:int -> int -> t
of_int ?scale i returns the decimal number i * 10**(-scale).
Raises Invalid_argument if scale < 0.
scale : Scaling of i (default: 0).
val add : t -> t -> t
add n m returns the sum of n and m.
val sub : t -> t -> t
sub n m returns the difference of n by m.
val mul : t -> t -> t
mul n m returns the product of n and m.
val div : t -> t -> t
div n m returns the quotient of the division of n by m.
val compare : t -> t -> int
compare n m returns 0 if x=y, a negative integer if x<y, and a positive integer if x>y.