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 make_printing_conf : sep:Separator.t -> plus_sign:bool -> num_of_digits:int -> rounding:rounding -> printing_conf

Make printing and rounding configuration

val mark_thousands : v:int -> sep:string -> string
val sep_comma : unit -> Separator.t

Premade separator configuration, e.g. 1000,0

val sep_comma_dot : unit -> Separator.t

Premade separator configuration, e.g. 1.000,0

val sep_comma_space : unit -> Separator.t

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

val sep_dot : unit -> Separator.t

Premade separator configuration, e.g. 1000.0

val sep_dot_comma : unit -> Separator.t

Premade separator configuration, e.g. 1,000.0

val sep_dot_space : unit -> Separator.t

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

val default_printing_conf : unit -> printing_conf

Default printing configuration

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 seal_quotient : printing_conf:printing_conf -> qv:Safemoney__Quotient.Make(Safemoney__.Qv).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.Make(Safemoney__.Qv)(Safemoney__.Zv).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.Make(Safemoney__.Qv).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.Make(Safemoney__.Qv)(Safemoney__.Zv).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_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_float_to_quotient : symbol:string -> decimal:string -> sep:Separator.t -> Safemoney__Quotient.Make(Safemoney__.Qv).t

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

val unsafe_float_to_discrete : scale:Safemoney__Discrete.Make(Safemoney__.Qv)(Safemoney__.Zv).Scale.t -> integer:int -> Safemoney__Discrete.Make(Safemoney__.Qv)(Safemoney__.Zv).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.Make(Safemoney__.Qv).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.Make(Safemoney__.Qv)(Safemoney__.Zv).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.