helperNumberAdd.js 458 B

123456789101112
  1. var helperNumberDecimal = require('./helperNumberDecimal')
  2. var toNumberString = require('./toNumberString')
  3. var multiply = require('./multiply')
  4. function helperNumberAdd (addend, augend) {
  5. var str1 = toNumberString(addend)
  6. var str2 = toNumberString(augend)
  7. var ratio = Math.pow(10, Math.max(helperNumberDecimal(str1), helperNumberDecimal(str2)))
  8. return (multiply(addend, ratio) + multiply(augend, ratio)) / ratio
  9. }
  10. module.exports = helperNumberAdd