multiply.js 620 B

1234567891011121314151617181920
  1. var helperNumberDecimal = require('./helperNumberDecimal')
  2. var toNumberString = require('./toNumberString')
  3. var toNumber = require('./toNumber')
  4. /**
  5. * 乘法运算
  6. *
  7. * @param { Number } num1 数值1
  8. * @param { Number } num2 数值2
  9. * @return {Number}
  10. */
  11. function multiply (num1, num2) {
  12. var multiplier = toNumber(num1)
  13. var multiplicand = toNumber(num2)
  14. var str1 = toNumberString(multiplier)
  15. var str2 = toNumberString(multiplicand)
  16. return parseInt(str1.replace('.', '')) * parseInt(str2.replace('.', '')) / Math.pow(10, helperNumberDecimal(str1) + helperNumberDecimal(str2))
  17. }
  18. module.exports = multiply