A template tag to parse and evaluate an expression consisting of
Decimal numbers and basic arithmetic
operators (+
, -
, *
, /
).
The default export uses the global Decimal
constructor, while
createDecimalTag
allows providing your own Decimal
implementation.
See the JSR docs on how to use packages from the JSR registry.
import d from "@nic/decimal-literal";
d`0.1 + 0.2`.equals(d`0.3`); // true
import d from "@nic/decimal-literal";
d`0.1`.toPrecision(20) === "1.1000000000000000000"; // true
import d from "@nic/decimal-literal";
const zeroPointTwo = d`0.2`;
d`0.1 + ${zeroPointTwo}`.equals(d`0.3`); // true