简体   繁体   中英

jquery how to use decimal numbers in if checkup

What is correct way to use decimal number with two decimal places in if checkup in jquery?

I have writted this way

$(".entered").change(function(){
 if(parseInt(this.value) > 39617756.85){
    alert('greater');
 } 
})

but it seems that it doeasn work: http://jsfiddle.net/dzorz/rremm/

用户parseFloat而不是parseInt

parseFloat(this.value) 

Use parseFloat for floating point precision:

$(".entered").change(function(){
    if (parseFloat(this.value) > 39617756.85) {
        alert('greater');
    } 
})
$(".entered").change(function(){
   if(parseFloat(this.value).toFixed(2) > 39617756.85){
      alert('greater');
   } 
})

worked for me

Try using parseFloat, like this:

$(".entered").change(function(){
 if(parseFloat(this.value) > 39617756.85){
    alert('greater');
 } 
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM