ts-cash
- Format numbers into currency format ๐
- Auto rounding โช
- Flexible settings ๐ช
- Unformatting ๐ป
- Convenient methods for calculation ๐ฆพ
- Contains 51 currencies, including 41 fiat currencies and 10 cryptocurrencies ๐
Installation
pnpm add ts-cash
Usage example
import { tsCash } from "ts-cash"
const amount1 = tsCash.format(10.01, "EUR");
console.log(amount1.val());
// โ
result: โฌ 10.01
const amount2 = tsCash.format(10.01, "EUR", {
mathSymbol: {
show: true,
},
currencySymbol: {
show: true,
place: "after",
space: true,
},
decimals: {
separator: ",",
max: 4,
fixed: true,
},
});
amount2.add(20.02);
amount2.sub(10);
amount2.custom((value) => value / 2);
console.log(amount2.val());
// โ
result: +10,0150 โฌ
console.log(tsCash.unformat("$ 100 000 00. 6"));
// โ
result: 10000000.6
const amount3 = tsCash.format(0.123456789123456789, "ETH", {
decimals: {
max: 6,
},
});
console.log(amount3.val());
// โ
result: ฮ 0.123457
Author
Vladislav Yemelyanov
Released under the MIT License.