helperNumberDivide.js 655 B

12345678910111213141516
  1. var helperNumberDecimal = require('./helperNumberDecimal')
  2. var toNumberString = require('./toNumberString')
  3. var multiply = require('./multiply')
  4. function helperNumberDivide (divisor, dividend) {
  5. var str1 = toNumberString(divisor)
  6. var str2 = toNumberString(dividend)
  7. var divisorDecimal = helperNumberDecimal(str1)
  8. var dividendDecimal = helperNumberDecimal(str2)
  9. var powY = dividendDecimal - divisorDecimal
  10. var isMinus = powY < 0
  11. var multiplicand = Math.pow(10, isMinus ? Math.abs(powY) : powY)
  12. return multiply(str1.replace('.', '') / str2.replace('.', ''), isMinus ? 1 / multiplicand : multiplicand)
  13. }
  14. module.exports = helperNumberDivide