(n: BigDecimal)
| 1020 | * @category conversions |
| 1021 | */ |
| 1022 | export const toExponential = (n: BigDecimal): string => { |
| 1023 | if (isZero(n)) { |
| 1024 | return "0e+0" |
| 1025 | } |
| 1026 | |
| 1027 | const normalized = normalize(n) |
| 1028 | const digits = `${abs(normalized).value}` |
| 1029 | const head = digits.slice(0, 1) |
| 1030 | const tail = digits.slice(1) |
| 1031 | |
| 1032 | let output = `${isNegative(normalized) ? "-" : ""}${head}` |
| 1033 | if (tail !== "") { |
| 1034 | output += `.${tail}` |
| 1035 | } |
| 1036 | |
| 1037 | const exp = tail.length - normalized.scale |
| 1038 | return `${output}e${exp >= 0 ? "+" : ""}${exp}` |
| 1039 | } |
| 1040 | |
| 1041 | /** |
| 1042 | * Converts a `BigDecimal` to a `number`. |
no test coverage detected