I use read "123" :: Int to read in Int from String. This works great for a simple case such as "123"; But it fails when the input is "12.34".
What do people usually do in such cases?
Edit: I also would like to know if there is a simple way to parse numbers with thousand separator such as "12,345"
This does not work, since 12.34 is not an Integer. You can parse this as a Float or a Decimal for example:
Prelude> read "12.34" :: Float
12.34
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With