TypeScript should support decimal values and arithmetic, similar to .NET's Decimal and/or Java's BigDecimal type. This would solve some serious problems when writing business applications in JavaScript.
For the following TS code:
var a = 0.1m; // notation is totally ad-hoc, just for the sake of the example code
var b = 0.2m;
var c = a + b;
if (c === 0.3m) {
console.log("OK");
}
the JS output should be something like this:
var a = new Decimal("0.1");
var b = new Decimal("0.2");
var c = Decimal.add(a, b);
if (Decimal.compare(c, new Decimal("0.3") === 0) {
console.log("OK");
}
where Decimal is the class that implements the decimal arithmetic and conversions.
There are a number of JS decimal implementations to take inspiration from:
https://github.com/MikeMcl/decimal.js
https://github.com/MikeMcl/bignumber.js
https://www.npmjs.com/package/jsdecimal
https://github.com/iriscouch/bigdecimal.js
TypeScript should support decimal values and arithmetic, similar to .NET's
Decimaland/or Java'sBigDecimaltype. This would solve some serious problems when writing business applications in JavaScript.For the following TS code:
the JS output should be something like this:
where
Decimalis the class that implements the decimal arithmetic and conversions.There are a number of JS decimal implementations to take inspiration from:
https://github.com/MikeMcl/decimal.js
https://github.com/MikeMcl/bignumber.js
https://www.npmjs.com/package/jsdecimal
https://github.com/iriscouch/bigdecimal.js