(n: BigDecimal)
| 1430 | * @since 3.11.0 |
| 1431 | */ |
| 1432 | export const toExponential = (n: BigDecimal): string => { |
| 1433 | if (isZero(n)) { |
| 1434 | return "0e+0" |
| 1435 | } |
| 1436 | |
| 1437 | const normalized = normalize(n) |
| 1438 | const digits = `${abs(normalized).value}` |
| 1439 | const head = digits.slice(0, 1) |
| 1440 | const tail = digits.slice(1) |
| 1441 | |
| 1442 | let output = `${isNegative(normalized) ? "-" : ""}${head}` |
| 1443 | if (tail !== "") { |
| 1444 | output += `.${tail}` |
| 1445 | } |
| 1446 | |
| 1447 | const exp = tail.length - normalized.scale |
| 1448 | return `${output}e${exp >= 0 ? "+" : ""}${exp}` |
| 1449 | } |
| 1450 | |
| 1451 | /** |
| 1452 | * Converts a `BigDecimal` to a JavaScript `number`. |
no test coverage detected