合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5 KiB

  1. // @ts-nocheck
  2. import {isNumber} from '../isNumber';
  3. // #ifdef APP-ANDROID
  4. import BigDecimal from 'java.math.BigDecimal'
  5. // import BigDecimal from 'java.math.BigDecimal'
  6. // import StringBuilder from 'java.lang.StringBuilder'
  7. // import java.math.BigDecimal;
  8. // #endif
  9. /**
  10. *
  11. * @param {number} num1 -
  12. * @param {number} num2 -
  13. * @returns {number}
  14. */
  15. export function floatMul(num1 : number, num2 : number) : number {
  16. if (!(isNumber(num1) || isNumber(num2))) {
  17. console.warn('Please pass in the number type');
  18. return NaN;
  19. }
  20. let m = 0;
  21. // #ifdef APP-ANDROID
  22. let s1 = BigDecimal.valueOf(num1.toDouble()).toPlainString(); //new UTSNumber(num1).toString() // //`${num1.toFloat()}`// num1.toString(),
  23. let s2 = BigDecimal.valueOf(num2.toDouble()).toPlainString(); //new UTSNumber(num2).toString() //`${num2.toFloat()}`//.toString();
  24. // #endif
  25. // #ifndef APP-ANDROID
  26. let s1:string = `${num1}`// num1.toString(),
  27. let s2:string = `${num2}`//.toString();
  28. // #endif
  29. try {
  30. m += s1.split('.')[1].length;
  31. } catch (error) { }
  32. try {
  33. m += s2.split('.')[1].length;
  34. } catch (error) { }
  35. // #ifdef APP-ANDROID
  36. return parseFloat(s1.replace('.', '')) * parseFloat(s2.replace('.', '')) / Math.pow(10, m);
  37. // #endif
  38. // #ifndef APP-ANDROID
  39. return Number(s1.replace('.', '')) * Number(s2.replace('.', '')) / Math.pow(10, m);
  40. // #endif
  41. }