Nodejs Utililty Methods Float Round

List of utility methods to do Float Round

Description

The list of methods to do Float Round are organized into topic(s).

Method

roundTo(num, dec)
Math.roundTo = function (num, dec) {
  return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
};
round(value)
Util.round = function(value) {
  return new Number((new Number(value)).toFixed(2));
};
roundTo (num, to)
Math.ceilTo = function roundTo (num, to) {
    if (num < to) {
        return to;
    var amount = to * Math.ceil(num / to);
    if (amount === 0) {
        amount = to;
    return amount;
...
roundTo(num, to)
Math.roundTo = function roundTo (num, to) {
    if (num < to / 2) {
        return 0;
    var amount = to * Math.round(num / to);
    if (amount === 0) {
        amount = to;
    return amount;
...
decRound(num, decimals)
function MyMath () {}
MyMath.decRound = function(num, decimals){
    return Math.round(num*Math.pow(10,decimals))/Math.pow(10,decimals);
$round(fractionalDigits)
Number.prototype.$round = function(fractionalDigits) {
    return parseFloat(this.toFixed(fractionalDigits));
};
ToRound(digits)
Number.prototype.ToRound = function (digits) {
    if (digits < 0 || digits > 10)
        return this;
    var pow10 = Math.pow(10, digits);
    return Math.round(this * pow10) / pow10;
};
round()
Number.prototype.round = function() {
  return Math.round(this);
};
round()
Number.prototype.round = function() {
  return Math.round(this);
};
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) {
...