MCPcopy Create free account
hub / github.com/Effect-TS/effect / toExponential

Function toExponential

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

Source from the content-addressed store, hash-verified

1430 * @since 3.11.0
1431 */
1432export 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`.

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