( value, precision, e, num, isDecimal, bits, ceil, roundingFunc, round, exponent, )
| 171 | * @returns {Object} Object with value and e properties |
| 172 | */ |
| 173 | export function applyPrecisionHandling( |
| 174 | value, |
| 175 | precision, |
| 176 | e, |
| 177 | num, |
| 178 | isDecimal, |
| 179 | bits, |
| 180 | ceil, |
| 181 | roundingFunc, |
| 182 | round, |
| 183 | exponent, |
| 184 | ) { |
| 185 | if (typeof value === "string") { |
| 186 | value = parseFloat(value); |
| 187 | } |
| 188 | |
| 189 | let result = value.toPrecision(precision); |
| 190 | |
| 191 | const autoExponent = exponent === -1 || isNaN(exponent); |
| 192 | |
| 193 | // Handle scientific notation by recalculating with incremented exponent |
| 194 | if (result.includes(E) && e < 8 && autoExponent) { |
| 195 | e++; |
| 196 | const { result: valueResult } = calculateOptimizedValue(num, e, isDecimal, bits, ceil); |
| 197 | let p; |
| 198 | if (round > 0) { |
| 199 | p = Math.pow(10, round); |
| 200 | } else { |
| 201 | p = 1; |
| 202 | } |
| 203 | let computed; |
| 204 | if (p === 1) { |
| 205 | computed = roundingFunc(valueResult); |
| 206 | } else { |
| 207 | computed = roundingFunc(valueResult * p) / p; |
| 208 | } |
| 209 | result = computed.toPrecision(precision); |
| 210 | } |
| 211 | |
| 212 | return { value: result, e }; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Optimized number formatting with locale, separator, and padding |
no test coverage detected