Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
16 lines
636 B
Plaintext
16 lines
636 B
Plaintext
import { Decimal } from "decimal.js";
|
|
import { memoize } from "@formatjs/fast-memoize";
|
|
/**
|
|
* Cached function to compute powers of 10 for Decimal.js operations.
|
|
* This cache significantly reduces overhead in ComputeExponent and ToRawFixed
|
|
* by memoizing expensive Decimal.pow(10, n) calculations.
|
|
*
|
|
* Common exponents (e.g., -20 to 20) are used repeatedly in number formatting,
|
|
* so caching provides substantial performance benefits.
|
|
*
|
|
* @param exponent - Can be a number or Decimal. If Decimal, it will be converted to string for cache key.
|
|
*/
|
|
export const getPowerOf10 = memoize((exponent) => {
|
|
return Decimal.pow(10, exponent);
|
|
});
|