Arbitrary-precision math for modern JavaScript.
Evaluate complex expressions, handle infinite precision, and eliminate native floating-point errors completely. Zero dependencies.
Evaluate complex expressions, handle infinite precision, and eliminate native floating-point errors completely. Zero dependencies.
Test the lexer, parser, and arbitrary-precision evaluator directly in your browser.
See how precision loss occurs natively and how PrecisionJS solves it.
Try these examples
Evaluate complex mathematical formulas with injected variables.
Early in my journey as a developer, I was building an educational app to help students with math. However, I continuously ran into a perplexing bug with basic addition—the infamous 0.1 + 0.2 !== 0.3 floating-point problem.
Soon after, I hit similar roadblocks with repeating decimals like 1/3 + 2/3, as well as native limits like Number.MAX_SAFE_INTEGER.
This wasn't a physics or finance app where rounding was an acceptable compromise; the math had to be completely exact. It had to be precise. That's when I decided to build PrecisionJS.
At its core, PrecisionJS parses every input as a rational number. A rational number is simply any number that can be expressed as a fraction a / b, where both a and b are integers and b is not zero.
PrecisionJS stores values exactly in this fractional format, representing the numerator and denominator using JavaScript's native BigInt.
Because BigInt has no artificial maximum limit, it dynamically scales to use as much memory as the system allows, guaranteeing infinite arbitrary precision without any data loss.
Crucially, this exact fractional format serves as the absolute source of truth. The decimal representation you see is only calculated on the fly as needed for printing or stringifying—meaning the internal math remains flawless, perfectly isolated from the inaccuracies of the original decimal inputs.