Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read/parse Int from String

Tags:

haskell

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"

like image 336
McBear Holden Avatar asked Nov 26 '25 02:11

McBear Holden


1 Answers

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
like image 151
Willem Van Onsem Avatar answered Nov 28 '25 14:11

Willem Van Onsem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!