Deci-mal
Simple Decimal type for Javascript.
Simple Decimal type which allows for:
- conversion from numbers;
- conversion from strings;
- specification of precision;
- changing of precision;
- addition of Decimals;
- subtraction of Decimals;
- multiplication of Decimals;
- division of Decimals.
When doing add, sub, mult, div-operators with two Decimals, the result will have the precision of the source Decimal with the highest precision.
Deci-mal uses an integer for internal storage.
Deci-mal is released under the Simplified BSD License.
Example usage
var decimal = ;var Decimal = decimaldecimal; // conversion from numbersvar a = decimal; // 20.00var b = decimal; // 40.1000 // conversion from stringsvar c = decimal; // 60.60 // specification of precisionvar d = 1; // 0.0 // changing of precisionb; // 40.10 // additiona; // 60.1000 // subtractiona; // -20.1000 // multiplicationa; // 802.0000 // divisiona; // 0.4988
Unit testing
Unit tests are built using Mocha.