MCPcopy Index your code
hub / github.com/Effect-TS/effect / toExponential

Function toExponential

packages/effect/src/BigDecimal.ts:1022–1039  ·  view source on GitHub ↗
(n: BigDecimal)

Source from the content-addressed store, hash-verified

1020 * @category conversions
1021 */
1022export 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`.

Callers 1

formatFunction · 0.85

Calls 4

isZeroFunction · 0.70
normalizeFunction · 0.70
absFunction · 0.70
isNegativeFunction · 0.70

Tested by

no test coverage detected