
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
@bignum/template-light
Advanced tools
Write formulas with template literals. (light version)
This is the light version of @bignum/template. It has significantly more limited functionality than @bignum/template, but is much smaller.
f`${0.3} - ${0.1}`
is easier to read than a statement like new MyNum(0.3).minus(0.1)
.)Note that although no rounding is performed during calculations, the calculation results are returned to
Number
, so values that cannot be held byNumber
may be rounded.If you want more operations and more rounding avoidance, consider using @bignum/template.
npm install @bignum/template-light
import { f } from "@bignum/template-light";
const result = f`${0.1} + ${0.1} * ${2}`;
console.log(result); // 0.3
// Prevent rounding errors by calculating with rational numbers using BigInt.
console.log(f`${0.2} + ${0.1}`); // 0.3
console.log(0.2 + 0.1); // 0.30000000000000004
Perform calculations using template literals.
Example:
import { f } from "@bignum/template-light";
console.log(f`${0.1} + ${0.2}`); // 0.3
The following operators are supported:
/* Arithmetic Operators */
// add
f`${0.1} + ${0.2}`; // 0.3
// subtract
f`${0.3} - ${0.1}`; // 0.2
// multiply
f`${0.07} * ${100}`; // 7
// divide
f`${0.6} / ${0.2}`; // 3
// modulo
f`${0.6} % ${0.2}`; // 0
/* Parentheses */
f`(${0.1} + ${0.2}) * ${10}`; // 3
f`${0.1} + ${0.2} * ${10}`; // 2.1
Substitutions in the template literal are considered operands.
f`${0.2} + ${0.1}`; // 0.3
FAQs
Write formulas with template literals.
The npm package @bignum/template-light receives a total of 14 weekly downloads. As such, @bignum/template-light popularity was classified as not popular.
We found that @bignum/template-light demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.