Stream: beginners

Topic: num


view this post on Zulip JesterXL (Dec 01 2022 at 16:24):

How do I convert a Str to a Num? I see various F64 and Nat's, but not sure how to get a Nat to an Int or Num.

view this post on Zulip JesterXL (Dec 01 2022 at 16:27):

Oh wait, disregard, this worked Str.toNat "10" |> Result.map \value -> value + 1

view this post on Zulip JesterXL (Dec 01 2022 at 16:27):

I guess I can treat Nat as an Int, ya? Helpful.

view this post on Zulip Ayaz Hafiz (Dec 01 2022 at 16:35):

There are a large number of Str -> Num methods of the form toI8, toI16, etc: https://www.roc-lang.org/builtins/Num#toI8

view this post on Zulip Ayaz Hafiz (Dec 01 2022 at 16:36):

There's nothing that goes from Str -> Num * though - you have to parse into a concrete number type


Last updated: Jul 05 2025 at 12:14 UTC