npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

exact-money

v0.1.0

Published

integer only token amounts. no floats, asset aware decimals, explicit rounding

Downloads

29

Readme

exact-money

integer only token amounts. no floats, asset aware decimals, explicit rounding.

npm i exact-money

why

0.1 + 0.2                       // 0.30000000000000004
1234567.123456789012345678      // 1234567.1234567891  <- 18 decimals do not fit

a float cannot hold a token balance. exact-money never converts to one — amounts are bigint in the smallest unit, and there is no toNumber.

use

import { asset } from 'exact-money'

const USDT = asset('USDT', 6)
const ETH  = asset('ETH', 18)

const a = USDT.parse('12.5')          // 12500000n
a.add(USDT.parse('1')).format()       // '13.500000'
a.format({ trim: true })              // '12.5'
a.bps(250).format({ trim: true })     // '0.3125'  (2.5%)

it will not let you mix assets

USDT.parse('1').add(USDC.parse('1'))
// MoneyError: cannot add USDT and USDC

same symbol on two chains is two assets:

const eth  = asset('USDT', 6, 'ethereum')
const tron = asset('USDT', 6, 'tron')
eth.parse('1').add(tron.parse('1'))
// MoneyError: cannot add USDT@ethereum and USDT@tron

and decimals are part of identity. this is a real bug shape — a config declaring XAUT0 with 6 decimals while the docs say 18:

asset('XAUT0', 6).equals(asset('XAUT0', 18))   // false
asset('XAUT0', 6).parse('1').raw               // 1000000n
asset('XAUT0', 18).parse('1').raw              // 1000000000000000000n

rounding is never implicit

USDT.parse('1').div(3)             // throws: result is not exact, pass a rounding mode
USDT.parse('1').div(3, 'floor')    // 0.333333
USDT.parse('1').div(4)             // 0.25, exact so no mode needed

modes: floor ceil trunc half-up half-even exact. negatives round the way you'd expect — floor on -3.5 is -4.

split with no dust

USDT.units(100n).split(3).map(p => p.raw)   // [34n, 33n, 33n]

the parts always add back up to the original. no rounding leak.

parsing refuses to lose digits

USDT.parse('1.1234567')
// MoneyError: 1.1234567 has 7 decimal places, USDT has 6

truncating here is how people lose money quietly. it throws instead.

rescale across precisions

const six = asset('T', 6), eighteen = asset('T', 18)
six.parse('1.5').rescale(eighteen).raw       // 1500000000000000000n
eighteen.units(1n).rescale(six)              // throws, would lose precision
eighteen.units(1n).rescale(six, 'floor').raw // 0n

api

| | | |---|---| | asset(symbol, decimals, chain?) | | | .parse('12.5') | string only, never a number | | .units(12500000n) | raw smallest unit | | add sub neg abs | same asset enforced | | mul(int) div(int, mode) | amount × amount is not money | | bps(points, mode?) | 250 is 2.5% | | split(n) | dust free | | rescale(asset, mode?) | | | cmp eq lt lte gt gte | | | format({ trim, group }) | exact, no exponent | | .raw | the bigint |

zero dependencies. types included.

licence

MIT