# Thread: how can check input is double or integer?

1. ## how can check input is double or integer?

how can check input is double or integer?

2. ## Re: how can check input is double or integer?

There may be a better way of doing this but you could try something like this. Convert the input to a string if it isn't already. Then you could search through each character. If there is a decimal point then it is a double value else it is an integer.

Hope this helps,

Regards Serb.

3. ## Re: how can check input is double or integer?

Originally Posted by SerbianSergeant
There may be a better way of doing this but you could try something like this. Convert the input to a string if it isn't already. Then you could search through each character. If there is a decimal point then it is a double value else it is an integer.

Hope this helps,

Regards Serb.
The String "123" can also be a double although there is no dot in it and "123E4" is only a double although there is also not dot in it.

kind regards,

Jos

4. ## Re: how can check input is double or integer?

Originally Posted by JosAH
The String "123" can also be a double although there is no dot in it and "123E4" is only a double although there is also not dot in it.

kind regards,

Jos
All integers can be doubles can't they? And good point, surely you could instead compare whether there are letters or a dot within the string? This may be incredibly inefficient, but just a suggestion.

Regards Serb.

5. ## Re: how can check input is double or integer?

Originally Posted by SerbianSergeant
All integers can be doubles can't they? And good point, surely you could instead compare whether there are letters or a dot within the string? This may be incredibly inefficient, but just a suggestion.

Regards Serb.
That doesn't always work either, e.g. 12345678901 can only be a double because it doesn't fit in an int. The best bet is to parse it as an int and when an Exception is thrown, parse it as a double; if still an Exception is thrown it isn't any of those types.

kind regards,

Jos

6. ## Re: how can check input is double or integer?

Good point, nice solution. HearT.Hunt3r, listen to Jos, forget about what i suggested ^^

7. ## Re: how can check input is double or integer?

i got my solution last night and did that checking by Double.parseDouble() and Integer.parseInteger() (try/exception) ... thx 2 all

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•