mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
Remove trailing zeros for decimals
This commit is contained in:
parent
42dbcfb46d
commit
b49282d4b7
16
packages/proto-signing/src/testdata/coins.json
vendored
16
packages/proto-signing/src/testdata/coins.json
vendored
@ -5,16 +5,16 @@
|
||||
[{"amount": "1000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "0.001 COSM"],
|
||||
[{"amount": "10000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "0.01 COSM"],
|
||||
[{"amount": "100000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "0.1 COSM"],
|
||||
[{"amount": "1000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "1.0 COSM"],
|
||||
[{"amount": "10000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "10.0 COSM"],
|
||||
[{"amount": "1000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "1 COSM"],
|
||||
[{"amount": "10000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 6 }, "10 COSM"],
|
||||
[{"amount": "1", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "0.01 COSM"],
|
||||
[{"amount": "10", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "0.1 COSM"],
|
||||
[{"amount": "100", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "1.0 COSM"],
|
||||
[{"amount": "1000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "10.0 COSM"],
|
||||
[{"amount": "10000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "100.0 COSM"],
|
||||
[{"amount": "100000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "1'000.0 COSM"],
|
||||
[{"amount": "1000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "10'000.0 COSM"],
|
||||
[{"amount": "10000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "100'000.0 COSM"],
|
||||
[{"amount": "100", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "1 COSM"],
|
||||
[{"amount": "1000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "10 COSM"],
|
||||
[{"amount": "10000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "100 COSM"],
|
||||
[{"amount": "100000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "1'000 COSM"],
|
||||
[{"amount": "1000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "10'000 COSM"],
|
||||
[{"amount": "10000000", "denom": "ucosm"}, { "denom": "COSM", "exponent": 2 }, "100'000 COSM"],
|
||||
[{"amount": "1", "denom": "point"}, { "denom": "POINT", "exponent": 0 }, "1 POINT"],
|
||||
[{"amount": "10", "denom": "point"}, { "denom": "POINT", "exponent": 0 }, "10 POINT"],
|
||||
[{"amount": "100", "denom": "point"}, { "denom": "POINT", "exponent": 0 }, "100 POINT"],
|
||||
|
@ -1,9 +1,9 @@
|
||||
[
|
||||
["0", "0.0"],
|
||||
["1", "1.0"],
|
||||
["12", "12.0"],
|
||||
["123", "123.0"],
|
||||
["1234", "1'234.0"],
|
||||
["0", "0"],
|
||||
["1", "1"],
|
||||
["12", "12"],
|
||||
["123", "123"],
|
||||
["1234", "1'234"],
|
||||
["0.1", "0.1"],
|
||||
["0.01", "0.01"],
|
||||
["0.001", "0.001"],
|
||||
|
@ -7,13 +7,11 @@ export function formatInteger(input: string): string {
|
||||
}
|
||||
|
||||
export function formatDecimal(input: string): string {
|
||||
let out = Decimal.fromUserInput(input, 18).toString(".", "'");
|
||||
if (out.indexOf(".") === -1) out += ".0";
|
||||
const out = Decimal.fromUserInput(input, 18).toString(".", "'");
|
||||
return out;
|
||||
}
|
||||
|
||||
export function formatCoin(input: Coin, unit: Pick<DenomUnit, "denom" | "exponent">): string {
|
||||
let out = Decimal.fromAtomics(input.amount, unit.exponent).toString(".", "'");
|
||||
if (unit.exponent !== 0 && out.indexOf(".") === -1) out += ".0";
|
||||
const out = Decimal.fromAtomics(input.amount, unit.exponent).toString(".", "'");
|
||||
return out + " " + unit.denom;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user