(n: number)
| 862 | * @category constructors |
| 863 | */ |
| 864 | export 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`. |
no test coverage detected