Convert a value to an integer - Node.js Number

Node.js examples for Number:Int

Description

Convert a value to an integer

Demo Code

Object.prototype.toInt = function() {
  var str = String(this);
  str = str.replace(/[^0-9-.]/g, "");
  var ret = parseInt(str, 10);
  if (isNaN(ret)) ret = 0;
  return ret;//from w ww  .j  a  v  a  2  s . c  om
}

Related Tutorials