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 :)

Recommended Answers

All 8 Replies

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

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....

What about 1e7 ?

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....)

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???

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.