decimal-js
decimal-js copied to clipboard
0.92 - 1 = 0.-8 ???
I am having the issue when I am doing Decimal(0.92).sub(1).
Decimal(0.92).sub(1) == "0.-8"
when it should equal
Decimal(0.92).sub(1) == "-0.8"
just hit same error, but my solution is different:
var neg_exp = function(str, position) {
position = Math.abs(position);
var sign = '';
if (str.charAt(0) === '-') {
sign = '-';
str = str.substr(1);
}
var offset = position - str.length;
var sep = INTERNAL_DECIMAL_SEPARATOR;
if(offset >= 0) {
str = zero(offset) + str;
sep = '0' + DECIMAL_SEPARATOR;
}
var length = str.length;
var head = str.substr(0, length - position);
var tail = str.substring(length - position, length);
return sign + head + sep + tail;
};