Skip to content
Michael M edited this page Apr 26, 2018 · 4 revisions

my-bignumber.js

import {BigNumber} from "bignumber.js"

BigNumber.set({
    DECIMAL_PLACES: 40,
    ROUNDING_MODE: BigNumber.ROUND_HALF_UP,
    EXPONENTIAL_AT: [-20, 30],
    RANGE: 1E9,
    CRYPTO: true,
    MODULO_MODE: BigNumber.ROUND_FLOOR,
    POW_PRECISION: 80,
    FORMAT: {
      decimalSeparator: '.',
      groupSeparator: ',',
      groupSize: 3,
      secondaryGroupSize: 0,
      fractionGroupSeparator: '',
      fractionGroupSize: 0
    },
    ALPHABET: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
  });
  
BigNumber.prototype.ceil = function (n) {
  return n.integerValue(BigNumber.ROUND_CEIL);
};

BigNumber.prototype.floor = function (n) {
  return n.integerValue(BigNumber.ROUND_FLOOR);
};

BigNumber.prototype.round = function (n) {
  return n.integerValue(BigNumber.ROUND_HALF_CEIL);
};

BigNumber.prototype.trunc = function (n) {
  return n.integerValue(BigNumber.ROUND_DOWN);
};

export default BigNumber;

main.js

import BigNumber from "./my-bignumber.js"

let x = new BigNumber('43253.589807643345');
x.ceil();            // '43254'
Clone this wiki locally