String to float

How can i convert string to float32? e.g.,
var a:String = "-0.01536663"
var a:String = "-0.01536663"
atol is not helping as it's used to convert to integers and not float.
3 Replies
hat
hat6mo ago
I don't think there is one yet (I may be mistaken). You can of course write your own, but it's surprisingly hard. If you don't care about perfectly adhering to float spec, though, you can do it pretty easily just by converting digits to ints, dividing by the appropriate power of 10, and summing
sora
sora6mo ago
Indeed, it’s horrifyingly difficult. But again, most ieee float things are like that.
sora
sora6mo ago
You can find a "naive" implementation here https://github.com/carlca/ca_mojo
GitHub
GitHub - carlca/ca_mojo
Contribute to carlca/ca_mojo development by creating an account on GitHub.
Want results from more Discord servers?
Add your server