Nodejs Number Calculate int()

Here you can find the source of int()

Method Source Code

var num = 5;//from w w  w. j a v  a 2s .  c  om
Number.prototype.int = function(){ 
         return parseInt(this) ;
}

Number.prototype.float = function(){ 
         return this.toFixed(2);
}



console.log(num.float());
console.log(num);
var num2 = 90.897;

console.log(num2.int());
console.log(num2.float());
console.log(num2);

Related

  1. getValue(arguments)
    var BigNumber = function(n){
      this.value = n.toString();
      this.getValue = function(){
        return this.value;
      this.getRealValue = function(){
        return Number(this.value);
      this.add = function(bnum){
    ...
    
  2. greaterThan(num)
    Number.prototype.greaterThan = function(num) {
        return this > num;
    
  3. gt(right) return this > right };
    Number.prototype.gt = function(right) { return this > right };
    Number.prototype.ge = function(right) { return this >= right };
    Number.prototype.lt = function(right) { return this < right };
    Number.prototype.le = function(right) { return this <= right };
    Number.prototype.eq = function(right) { return this == right };
    Number.prototype.ne = function(right) { return this != right };
    
  4. hasDiv( n )
    Number.prototype.hasDiv = function( n ) {
      return Number.isInteger( this / n )
    function sum( ary ) {
      var out = 0
      for (var n in ary)  {
        out += ary[n]
      return out
    ...
    
  5. hasMult( n )
    Number.prototype.hasMult = function( n ) {
      return Number.isInteger( this / n )
    function fun100() {
      out = []
      for ( var i = 1; i <= 100; i++ ) {
        if ( i.hasMult(3) ) {
          out.push['Fizz']
        else if ( i.hasMult(5) ) {
          out.push['Buzz']
        else if ( i.hasMult(5) && i.hasMolt(3) ) {
          out.push["Fizzbuzz"]
        else {
          out.push( i.toString() )
      return out
    
  6. intToHSL()
    Number.prototype.intToHSL = function() {
        var shortened = this % 360;
        return "hsl(" + shortened + ",45%,56%)";
    };
    
  7. max(maximum)
    Number.prototype.max = function(maximum) {
        if (this.valueOf() > maximum){
          return maximum;
        } else {
          return this.valueOf();
    };
    
  8. min(minimum)
    Number.prototype.min = function(minimum) {
        if (this.valueOf() < minimum){
          return minimum;
        } else {
          return this.valueOf();
    };
    
  9. modNumber.prototype.mod || (n)
    Number.prototype.mod = Number.prototype.mod || function(n) {
      return ((this%n)+n)%n;