Skip to content

Commit

Permalink
Merge pull request #30 from bvotteler/fix-increase-to-string-exponent…
Browse files Browse the repository at this point in the history
…-cutoff

Fix: increase to string exponent cutoff
  • Loading branch information
bvotteler authored Feb 7, 2023
2 parents 924663f + 61ea1de commit 6f01ffb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@interlay/monetary-js",
"version": "0.7.0",
"version": "0.7.1",
"main": "build/index.js",
"description": "JavaScript library to safely handle currency and cryptocurrency amounts",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/monetary.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Big, { RoundingMode, BigSource } from "big.js";

Big.DP = 100;
Big.NE = -20;
Big.PE = 20;
Big.NE = -39;
Big.PE = 39;

export interface Currency {
readonly name: string;
Expand Down
16 changes: 16 additions & 0 deletions test/monetary.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Big, { BigSource, RoundingMode } from "big.js";
import { expect } from "chai";
import * as fc from "fast-check";
import { Polkadot } from "../src/currencies";

import { Currency, MonetaryAmount } from "../src/monetary";

Expand Down Expand Up @@ -69,6 +70,21 @@ describe("MonetaryAmount", () => {
})
);
});

it("should show full amount or scientific notation as expected", () => {
// expected cutoff is 39
const above = Big(1e39);
const below = above.sub(1);

const amountAbove = new MonetaryAmount(Polkadot, 0).withAtomicAmount(above);
const amountBelow = new MonetaryAmount(Polkadot, 0).withAtomicAmount(below);

expect(amountAbove.toString(true)).to.eq("1e+39");

// 39 times the '9' character
const expectedBelow = "9".repeat(39);
expect(amountBelow.toString(true)).to.eq(expectedBelow)
});
});

describe("toHuman", () => {
Expand Down

0 comments on commit 6f01ffb

Please sign in to comment.