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

Function safeFromNumber

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

Source from the content-addressed store, hash-verified

862 * @category constructors
863 */
864export const safeFromNumber = (n: number): Option.Option<BigDecimal> => {
865 if (!Number.isFinite(n)) {
866 return Option.none()
867 }
868
869 const string = `${n}`
870 if (string.includes("e")) {
871 return fromString(string)
872 }
873
874 const [lead, trail = ""] = string.split(".")
875 return Option.some(make(BigInt(`${lead}${trail}`), trail.length))
876}
877
878/**
879 * Parses a numerical `string` into a `BigDecimal`.

Callers 1

unsafeFromNumberFunction · 0.85

Calls 3

splitMethod · 0.80
fromStringFunction · 0.70
makeFunction · 0.70

Tested by

no test coverage detected