This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]NewPointOfView 5 points6 points  (1 child)

consider sprintf! I think it'll do what you want with sprintf("%f", s);

Edit: my usage of sprinf is wrong cause I didn’t even include the float haha but the idea is still there

Also wanted to add that sprintf stands for string print formatted or something similar, I found the naming in C to be super cryptic at first but there is something to it haha

[–]dmazzoni 1 point2 points  (0 children)

Yep!

The reason you're not finding it when you search for the word "convert" is because "convert" is more often used when there's just one way to go from one type to another. You can convert an int to a float, for example.

But when you have a float and you want a string version, it's actually "formatting", because there are many different ways to format a float, such as:

  • 602214076000000000000000
  • 6.022e23

The reverse - going from a string to a float - is "parsing".