BigDecimal subtraction
2022年5月1日小于 1 分钟
BigDecimal subtraction
Question
This is a follow-up on 126. BigDecimal addition
In this problem, you are asked to implement the subtraction of two decimals with arbitrary digits.
subtract('-999999999999999999', '-1')
// '-999999999999999998'
subtract(
'-999999999999999999.999999999999999999999999999999',
'1.0000000000000000000000000001')
// '-1000000000000000001.000000000000000000000000000099'
subtract(
'999999999999999999.999999999999999999999999999999',
'-1.000000000000000000000000000001')
// '1000000000000000001'
- This problem covers 77. implement BigInt subtraction with sign.
- trailing zeroes in the result should be removed.
Code
/**
* @param {string} num1
* @param {string} num2
* @return {string}
*/
function subtract(num1, num2) {
// your code here
}