0

Hi,

I was wondering if its possible to get the integer OR float value of a string. If I know it's an integer I can do int x = atoi(str) and atof if its a float but what do I do if I don't know what it is (in other words if I don't know if it's a float or an integer)?

Basically I have a string with two numbers (and a space between them) and I want to get the numbers, add them and print the result. (I know how to split the string)

Any ideas on that will be great. Thanks :)

5
Contributors
8
Replies
9
Views
9 Years
Discussion Span
Last Post by Duoas
0

Why worry if the input is integer or floating point? Treat all as floating point and you have no problems.

0

vmanes is right..

still if you want to keep both of them (i.e. int and float) then you may check for the '.' decimal in the string using iterators or anything else to traverse the string....

0

I thought hacker speak wasn't allowed/permitted/desired here?

(Sorry, couldn't resist ;). I know your example is an exponential form, but it looks like....)

0

What about 1e7 ?

didnt get you???

I thought hacker speak wasn't allowed/permitted/desired here?

(Sorry, couldn't resist ;). I know your example is an exponential form, but it looks like....)

didnt get you too???

0

lol thanks for the replies I'll make them floats and play around with the decimals

0

LOL :icon_lol:

RajatC Read here and here.

The joke is that the floating-point number 10,000,000, written as "1e7", looks like leetspeak.

This is a forum for programmers and hackers, not script kiddies and warez wannabies, so leetspeek is expressly verboten.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.