JS compares the size of two numbers; compares the size of two decimals (super easy to use!!!)

Compare the size of two numbers:

The integers are as follows:

if(parseInt(xxx)>parseInt(xxxx)){

}

Decimals can be like this.

if(parseFloat(xxx)>parseFloat(xxxx)){

}

Wrong wording:

<script> 
 function check() 
 { 
 var num1=document.form1.num1.value; 
 var num2=document.form1.num2.value; 
 if(num2>num1) <!-错误写法-->
 { 
 alert('num2 > num1!'); 
 return false; 
 } 
 return true; 
 } 
 </script> 

 

Guess you like

Origin blog.csdn.net/qq_40055200/article/details/114637793