Money Package

Difference between version 0 and 1 - Previous - Next
The money package is a simple and flexible money-handling package built using the NX framework and math::decimal. It provides utilities for common monetary calculations like addition, subtraction, percentages, and rounding (half-even).

https://github.com/Siqsuruq/money-tcl-package%|%Money Package GitHub%|%
https://github.com/Siqsuruq/money-tcl-package/releases/download/v1.0.23/money-1.0.23.zip%|%Money package zip%|%

**Requirements**

   * Tcl 9.0 (tested with tclsh9.0)
   * nx
   * math::decimal (tcllib)

**Methods**

   * add, subtract, multiply, divide, round
   * addPercent, subtractPercent, getPercent, get100Percent
   * change, average, percentagechange
   * withSeparators (display formatting with thousands separators)
   * setRoundDigits, getRoundDigits, version

**Example**

======
package require nx
package require math::decimal
package require money

puts [money add 100.125 200.375]          ;# 300.50
puts [money addPercent 100 15]            ;# 115.00
puts [money get100Percent 118 18]         ;# 100.00
puts [money withSeparators 1234567.891]   ;# 1,234,567.89

money setRoundDigits 3
puts [money add 100.125 200.375]          ;# 300.500
======

Values must be plain decimals (1000.50), not 1,000.50.

**Installation**

With TPM (Tcl Package Manager), which installs from the Public Tcl Package Repository:

======
tclsh main.tcl
> install money
======

https://code.cloudz.cv/tpm%|%TPM - Tcl Package Manager%|%

https://tclrepo.daidze.org/%|%Public Tcl Package Repository%|%

https://tclrepo.daidze.org/api/v2/download/package/d222f0cb-d638-4533-8744-c1086212b54d%|%Money 1.0.3 download (PTPR)%|%

Or download the zip above and add its parent directory to auto_path:

======
lappend auto_path /path/to/parent/of/money-1.0.3
package require money
======