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

Function fromNumber

packages/effect/src/BigDecimal.ts:1235–1247  ·  view source on GitHub ↗
(n: number)

Source from the content-addressed store, hash-verified

1233 * @since 2.0.0
1234 */
1235export const fromNumber = (n: number): Option.Option<BigDecimal> => {
1236 if (!Number.isFinite(n)) {
1237 return Option.none()
1238 }
1239
1240 const string = `${n}`
1241 if (string.includes("e")) {
1242 return fromString(string)
1243 }
1244
1245 const [lead, trail = ""] = string.split(".")
1246 return Option.some(make(BigInt(`${lead}${trail}`), trail.length))
1247}
1248
1249/**
1250 * Parses a decimal string into a `BigDecimal` safely.

Callers 1

fromNumberUnsafeFunction · 0.70

Calls 5

someMethod · 0.80
fromStringFunction · 0.70
makeFunction · 0.70
BigIntInterface · 0.70
splitMethod · 0.45

Tested by

no test coverage detected