Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 000,000,000.00 greater than zero?

I have an input mask on my text box like

        000,000,000.00

I have the following jQuery code to check the value of text box before submitting data.

    var txt_box = $('#txt_box').attr('value');

     if(txt_box <= 0 )

But now even if I didn't input any data, the box remains empty with only the input mask, data is submitting.

like image 536
air Avatar asked Jul 24 '10 09:07

air


People also ask

How do you know if a value is greater than 0?

An alternative and more common approach is to use the less than or equals to sign. To check if a number is not greater than 0 , check if the number is less than or equal to 0 , e.g. num <= 0 . If the condition returns true , the number is not greater than 0 . Copied!

Is zero less than or equal to zero?

No zero is not less then zero, i <= 0 becomes 1 because zero is less than or equal to zero. Save this answer.


2 Answers

First: Separating floating points with a dot notation is required.

Second: You are checking for equal or less not just less than.

Third: Use parseInt() or parseFloat() to convert that input string into a Number.

Example:

var txt_box = $('#txt_box').attr('value').replace(/,/g, ".");
    if(parseFloat(txt_box) <= 0 )
like image 160
jAndy Avatar answered Oct 31 '22 14:10

jAndy


You use <= instead < Anyway, you should parse value to number too.

like image 25
IProblemFactory Avatar answered Oct 31 '22 15:10

IProblemFactory