Casting a variable as the correct type when it is read in as a string #3100
-
Say I have parsed a CSV and ended up with a load of strings. Some might look like this: Apologies for the newb question, but if someone could gently shove me in the right direction, I'd greatly appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could use the std lib's float module! Just add |
Beta Was this translation helpful? Give feedback.
You could use the std lib's float module! Just add
import gleam/float
then callfloat.parse("123.4")
. You'll then have to handle the result type, I recommend reading that section of the tour and looking at the std lib result module on hex docs if you're not familiar :) you can use theparse
function from the int std lib module as well