Nodejs Float Round round(places)

Here you can find the source of round(places)

Method Source Code

Number.prototype.round = function(places) {
    return +(Math.round(this + "e+" + places)  + "e-" + places);
}

function fractionToFloat(str)
{
    // Check for complex fraction
var complexParts = str.split(' ');

var result = 0;//from  w  ww .  j a  v  a  2 s . c  om
var f;

if (complexParts.length == 1) {
    f = complexParts[0];
}
else {
    result += parseInt(complexParts[0]);
    f = complexParts[1];
}

var parts = f.split('/');

if (parts.length == 1) {
    // No fractions
    return str;
}
else {
    result += parseInt(parts[0]) / parseInt(parts[1]);
}

return result;
}

Related

  1. round()
    Number.prototype.round = function() {
      return Math.round(this);
    };
    
  2. round()
    Number.prototype.round = function() {
      return Math.round(this);
    };
    
  3. round(d)
    Number.prototype.round = function(d) {
      const string_number = String(this)
      const split_string = string_number.split('.')
      if (split_string.length === 1) return this
      const integer_chunk = split_string[0]
      if (!d) return integer_chunk
      const decimal_chunk = split_string[1]
      const determinig_digit = parseInt(decimal_chunk[d])
      if (determinig_digit < 5) {
    ...
    
  4. round(decimals)return round(this,decimals);}
    exports.round = function(number,decimals){return round(number,decimals);}
    Number.prototype.round = function(decimals){return round(this,decimals);}
    var round = function(number,decimals){
      if(!isNaN(number)){
        var d = 1;
        if(!isNaN(decimals)){
          d = Math.pow(10,decimals)
        return Math.round(number * d)/d;
    ...
    
  5. round(dp)
    Number.prototype.round = function(dp) {
        multiplier = Math.pow(10,dp);
        return Math.round(this*multiplier) / multiplier;
    
  6. round(precision)
    Number.prototype.round = function(precision) {
      var factor = Math.pow(10, precision || 0);
      return Math.round(this * factor) / factor;
    };
    
  7. round(precision)
    Number.prototype.round = function(precision){
      if (Object.isUndefined(precision)){
        return Math.round(this);
      precision = Math.pow(10, precision);
      return Math.round(this * precision) / precision;
    };
    
  8. round(precision)
    Number.prototype.round = function (precision) {
        precision = Math.pow(10, precision || 0);
        return Math.round(this * precision) / precision;
    };
    
  9. round5()
    Number.prototype.round5 = function() {
      return ((this)- (this % 5));