126. BigDecimal addition

Is this helpful ?

from all members: - accepted / - tried

As you know, number data type in JavaScript cannot represent (all) float numbers accurately due to binary nature.

For some basic calculations, you might use Number.prototype.toFixed() to overcome this, yet for more extreme cases that requires perfect accuracy, it is not enough.

Proposal of BigDecimal to JavaScript is still at an early stage, before it is adopted, you can use other libraries like Big.js.

In this problem, you are asked to implement the addition of two decimals with arbitrary digits.

add('-999999999999999999', '-1')
// '-1000000000000000000'

// '-999999999999999998.999999999999999999999999999899'

// '1000000000000000001'
  1. This problem covers 76. implement BigInt addition with sign.
  2. trailing zeroes in the result should be removed.

Let's try to solve this problem within 20 mintues.