package safemoney

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type rounding =
  1. | Up
    (*

    decimal digits ignored

    *)
  2. | Down
    (*

    decimal digits ignored

    *)
  3. | Nearest
    (*

    decimal digits ignored

    *)
  4. | NearestHalfToEven
    (*

    decimal digits ignored

    *)
  5. | TowardsZero
    (*

    decimal digits ignored

    *)
  6. | WithDecimalPrecision
    (*

    rounding up to number of decimal digits provided

    *)
  7. | Truncate
    (*

    rounding down to number of decimal digits provided

    *)

Float round strategies

module Separator : sig ... end

Separator Configuration

type printing_conf = {
  1. separator : Separator.t;
  2. plus_sign : bool;
  3. num_of_digits : Stdint.Uint8.t;
  4. rounding : rounding;
}

Printing and rounding configuration

val sep_comma : Separator.t

Premade separator configuration, e.g. 1000,0

val sep_comma_dot : Separator.t

Premade separator configuration, e.g. 1.000,0

val sep_comma_space : Separator.t

Premade separator configuration, e.g. 1_000,0

val sep_dot : Separator.t

Premade separator configuration, e.g. 1000.0

val sep_dot_comma : Separator.t

Premade separator configuration, e.g. 1,000.0

val sep_dot_space : Separator.t

Premade separator configuration, e.g. 1_000.0

val default_printing_conf : printing_conf

Default printing configuration

val mark_thousands : v:int -> sep:string -> string

Mark a positive integer value with thousand separator configuration e.g. mark_thousands ~v: 1234567 ~sep: "," would print "1,234,567"

val q_to_decimal : printing_conf:printing_conf -> qv:Q.t -> string

Convert a rational value to string representation of a float value with a printing configuration. e.g. let sep_dot_comma = Separator.make_exn ('.', Some ',') in let printing_conf = { separator = sep_dot_comma; plus_sign = true; num_of_digits = Uint8.of_int 4; rounding = Truncate } in q_to_decimal ~printing_conf: printing_conf ~qv: (Utils.make_q "-1234567/7") would print "-176366.7142"

val z_to_decimal : Z.t -> Base.String.t

Convert an integer value to float/decimal value of string rep, not used internally but provide mere convenience

val unsafe_decimal_to_q : decimal:string -> sep:Separator.t -> (string, string) result

Parse the string representation of a float value with printing configuration e.g. let sep = Separator.make_exn ('.', Some ',') in unsafe_decimal_to_q ~decimal : "+123,456.789" would convert value to "123456.789"

val unsafe_integer_to_z : int -> string

Unsafely convert a float/decimal value of string rep to integer value. It is unsafe in a sense that the origin of float/decimal is deemed to be unverified by default and might be as a result of lossy operations.

val seal_quotient : printing_conf:printing_conf -> qv:Safemoney.Quotient.t -> string

Convert quotient value to the string representaion of a float value with a printing configuration. This should be used as the final step after all operations have been carried out.

val seal_discrete : printing_conf:printing_conf -> dv:Safemoney.Discrete.t -> string

Convert discrete value to the string representaion of a float value with a printing configuration. This should be used as the final step after all operations have been carried out.

val seal_exchange : printing_conf:printing_conf -> xchg:Safemoney.Exchange.t -> string

Convert exchange value to the string representaion of a float value with a printing configuration. This should be used as the final step after all operations have been carried out.

val seal_scale : printing_conf:printing_conf -> scale:Safemoney.Discrete.Scale.t -> string

Convert scale value to the string representaion of a float value with a printing configuration. This should be used as the final step after all operations have been carried out.

val unsafe_float_to_quotient : symbol:string -> decimal:string -> sep:Separator.t -> Safemoney.Quotient.t

Unsafely convert a float/decimal value of string rep to quotient value. It is unsafe in a sense that the origin of float/decimal is deemed to be unverified by default and might be as a result of lossy operations.

val unsafe_float_to_discrete : scale:Safemoney.Discrete.Scale.t -> integer:int -> Safemoney.Discrete.t

Unsafely convert a integer value of string rep to discrete value. It is unsafe in a sense that the origin of the integer is deemed to be unverified by default and might be as a result of lossy operations.

val unsafe_float_to_exchange : src:string -> dst:string -> decimal:string -> sep:Separator.t -> Safemoney.Exchange.t

Unsafely convert a float/decimal value of string rep to exchange value. It is unsafe in a sense that the origin of float/decimal is deemed to be unverified by default and might be as a result of lossy operations.

val unsafe_float_to_scale : symbol:string -> unit:string -> decimal:string -> sep:Separator.t -> Safemoney.Discrete.Scale.t

Unsafely convert a float/decimal value of string rep to scale value. It is unsafe in a sense that the origin of float/decimal is deemed to be unverified by default and might be as a result of lossy operations.

OCaml

Innovation. Community. Security.