Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integer Comparison

Tags:

javascript

I need to compare two Integers which could exceed Integer range limit. How do I get this in javascript. Initially, I get the value as String, do a parseInt and compare them.

var test = document.getElementById("test").value;
var actual = document.getElementById("actual").value;
if ( parseInt(test) == parseInt(actual)){
  return false;  
}

Any options to use long ? Also, which is best to use parseInt or valueOf ??

Any suggestions appreciated,

Thanks

like image 913
User Avatar asked Jan 17 '23 05:01

User


1 Answers

You'd better to assign the radix. Ex. parseInt('08') will give 0 not 8.

if (parseInt(test, 10) === parseInt(actual, 10)) {
like image 100
xdazz Avatar answered Jan 18 '23 22:01

xdazz