JS, how to tell if a number is not a small amount? If decimals, how to judge it is several decimal places reserved n decimal places

 

<Script type = "text / JavaScript"> var X = 4.23323; // testing digital var Y = String (X) .indexOf ( ".") +. 1; // Get the decimal point var COUNT = String (X) .length - Y; // number after the decimal point obtaining IF (Y> 0 ) { 
        Alert ( "decimal figure is, there is" + count + "decimal" ); 
    } the else { 
        Alert ( "not a decimal" ); 
    } </ Script>

    
    
    
    

 

// Reserved n decimal 
function roundFun (value, n) {
     return Math.round (Math.pow * value (10, n)) / Math.pow (10, n); 
}

 

 

 

 

Guess you like

Origin www.cnblogs.com/wuss/p/11327026.html