File: sumofmoney.ml

package info (click to toggle)
misery 0.2-1.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 380 kB
  • ctags: 298
  • sloc: ml: 1,295; xml: 180; makefile: 94
file content (33 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
type amount = int * string
type default_units_amount = int

let create sum str = (sum, str)
let to_string (amount, str) =
  if str <> "" then (Misc.format_money amount) ^ " (" ^ str ^ ")"
  else Misc.format_money amount

let zero = (0, "0.00")
let zero_default = 0
let is_negative (sum, _) = sum < 0
let add (sum, str) sum' = sum + sum'
let negate (sum, str) =
  if str = "" then (-sum, str)
  else
  begin
    if sum < 0 then
      (-sum, String.sub str 1 (String.length str - 1))
    else
      (-sum, "-" ^ str)
  end
let to_string_default = Misc.format_money
let non_negative_default sum = (not (sum <= -1))
let very_negative_default sum = sum < -5000
let negate_default sum = -sum
let scale_default numerator denominator sum =
  truncate (numerator /. denominator *. (float sum))
let abs_default a = abs a
let add_default a b = a + b
let subtract_default a b = a - b
let default_to_normal sum = (sum, "")
let is_zero (sum, _) = (sum = 0)