allocationText fix

This commit is contained in:
tim
2025-03-10 21:12:52 -04:00
parent ebf70dd10c
commit b2ed48492b
8 changed files with 25 additions and 13 deletions

View File

@@ -251,3 +251,11 @@ export function computeInterceptSlope(time0, price0, time1, price1) {
export function defined(v) {
return v !== undefined && v !== null
}
export function toPrecision(value, significantDigits = 3) {
if (!isFinite(value)) return value.toString(); // Handle Infinity and NaN
if (value === 0) return "0"; // Special case for 0
const magnitude = Math.floor(Math.log10(Math.abs(value)));
const decimalsNeeded = Math.max(0, significantDigits - 1 - magnitude);
return value.toFixed(decimalsNeeded); // Use toFixed to completely avoid scientific notation
}