<html>
<script type="text/javascript">
Multiply (3, 0.0001); multiply(3, 0.0001); multiply(3, 0.0001); multiply(3, 0.0001); 0.0003 String. The prototype. The substring () (HTTP: / / https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/sub String) Number.prototype.toFixed()(https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Number/toFix Ed) // */
function multiply(a, b) {
    a = a.toString();
    b = b.toString();
    var aLen = a.substring(a.indexOf('. ') + 1).length;
    var bLen = b.substring(b.indexOf('. ') + 1).length; 
    
    return (a * b).toFixed(Math.max(aLen, bLen));
    /* The number of decimal places is 0.0003000, and the number of decimal places is 0.0003000. Convert to 0.0003 */
}

console.log( "Solution:" + multiply( 3.0.0001 ));
console.log( 3 * 0.0001 );

console.log( "Solution: " + multiply( 3.0001.0.0002 ));
console.log( 3.0001 * 0.0002 );
</script>
</html>
Copy the code