How to use the decimal.js.Decimal function in decimal

To help you get started, we’ve selected a few decimal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pmiddend / piggybudget / src / screens / History.tsx View on Github external
private onEdit(index: number) {
		const t = (this.props.transactions.get(index) as Transaction);
		this.props.navigation.navigate("Modify", {
			editTransaction: {
				index,
				transaction: t,
			},
			isExpense: new Decimal(t.amount).isNegative(),
		});
	}
github pmiddend / piggybudget / src / Reducer.ts View on Github external
function createDailyTransaction(
	day: moment.Moment,
	incomeType: string,
	income: Decimal): Transaction {
	return {
		amount: incomeType === "daily" ? income : new Decimal(income).div(new Decimal(day.daysInMonth())).toDecimalPlaces(2),
		comment: "AUTOMATIC",
		date: day.toDate().getTime(),
	};
}
github wavesplatform / WavesExplorerLite / src / js / shared / Money.js View on Github external
static fromCoins = (amount, currency) => {
        currency = currency || {};
        if (currency.precision === undefined)
            throw new Error('A valid currency must be provided');

        if (amount instanceof BigNumber)
            amount = amount.toString();

        amount = new Decimal(amount);
        amount = amount.div(Math.pow(10, currency.precision));

        return new Money(amount, currency);
    };
github wavesplatform / WavesExplorerLite / src / js / shared / OrderPrice.js View on Github external
const normalizePrice = (price, pair) => {
    if (price instanceof BigNumber)
        price = price.toString();

    return new Decimal(price)
        .div(MATCHER_SCALE)
        .div(Math.pow(10, pair.priceAsset.precision - pair.amountAsset.precision));
};
github XiaoMi / hiui / components / counter / Counter.js View on Github external
onClick={e => {
              let value = new Decimal(valueTrue).plus(step).valueOf()
              if (isAddDisabled) {
                return
              }
              if (step > 0) {
                if (this.willReachMax) {
                  value = max
                }
              } else {
                if (this.willReachMin) {
                  value = min
                }
              }
              this.update(value)
            }}
          >
github XiaoMi / hiui / components / counter / Counter.js View on Github external
onClick={e => {
              let value = new Decimal(this.getInputNumber()).minus(step).valueOf()
              if (isMinusDisabled) {
                return
              }
              if (step > 0) {
                if (this.willReachMin) {
                  value = min
                }
              } else {
                if (this.willReachMax) {
                  value = max
                }
              }
              this.update(value)
            }}
          >
github gluon-project / gluon-rxp / src / Utils / number.ts View on Github external
export const numberToString = (val1: string, val2: number): string => {
  const amount = val1 ? val1 : '0'
  const decimals = new Decimal(val2 ? val2 : 0)
  const bigAmount = new Decimal(amount)
  const bigMultiplier = new Decimal(10).pow(decimals)
  return  bigAmount.div(bigMultiplier).toFixed()
}
github wavesplatform / WavesExplorerLite / src / js / shared / Money.js View on Github external
constructor(amount, currency) {
        if (amount === undefined)
            throw new Error('Amount is required');

        if (currency === undefined)
            throw new Error('Currency is required');

        if (amount instanceof BigNumber)
            amount = amount.toString();

        this.amount = new Decimal(amount)
            .toDecimalPlaces(currency.precision, Decimal.ROUND_FLOOR);
        this.currency = currency;
    }
github greymass / eos-voter / app / shared / utils / EOS / Account / Stats.js View on Github external
totalTokens() {
    const totalStaked = this.totalStakedToSelf().plus(this.totalStakedToOthers());
    const totalBeingUnstaked = this.totalBeingUnstaked();
    const totalTokens = this.tokens()[this.chainSymbol] || new Decimal(0);

    return totalStaked.plus(totalBeingUnstaked).plus(totalTokens);
  }

decimal

Simple decimal arithmetic for the browser and node.js!

MIT
Latest version published 13 years ago

Package Health Score

48 / 100
Full package analysis

Popular decimal functions