Results 1 to 5 of 5
  1. #1
    heartysnowy's Avatar
    heartysnowy is offline Member
    Join Date
    Nov 2008
    Posts
    37
    Rep Power
    0

    Default validate between int and double

    Hi all,

    I would like to put a simple validation on the user input of which the validation could determine whether the input is an integer or double.

    I had tried googling on various topics but really can't get to the accurate answers and which is why I come here to seek advice.

    Is there way to implement that validation withouth using Math.floor method?
    (the code below is the one found on yahoo qna section and i got puzzled)
    Java Code:
    f (Math.floor(a)==a) {
    // a is an integer
    }
    else
    {
    // a's not an integer 
    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Uhm

    (int) a == a

    maybe?

  3. #3
    mrmatt1111's Avatar
    mrmatt1111 is offline Senior Member
    Join Date
    Aug 2009
    Location
    San Jose, CA, USA
    Posts
    320
    Rep Power
    5

    Default

    If the input was a string:

    Java Code:
    int value = 0;
    try
    {
        value = Integer.parseInt(input);
    }
    catch(Exception e)
    {
       System.out.println("Input was not an Integer");
    }
    Last edited by mrmatt1111; 10-05-2009 at 07:06 PM.
    My Hobby Project: LegacyClone

  4. #4
    heartysnowy's Avatar
    heartysnowy is offline Member
    Join Date
    Nov 2008
    Posts
    37
    Rep Power
    0

    Default

    hello masijade.. thnks for the swift reply again but i m kind of dumb in java so could u make it more comprehensive... xD
    as i hv stated early, I would like to avoid using Math() function to implement my validation... so would u like to suggest other way round?

  5. #5
    heartysnowy's Avatar
    heartysnowy is offline Member
    Join Date
    Nov 2008
    Posts
    37
    Rep Power
    0

Similar Threads

  1. Check if double is double
    By marshalthrone in forum New To Java
    Replies: 8
    Last Post: 09-30-2009, 02:51 PM
  2. Replies: 5
    Last Post: 03-21-2009, 09:32 PM
  3. Double.valueOf() vs Double.parseDouble()
    By greenbean in forum New To Java
    Replies: 10
    Last Post: 01-12-2009, 08:39 AM
  4. repaint validate doLayout
    By Gajesh Tripathi in forum AWT / Swing
    Replies: 1
    Last Post: 10-27-2007, 06:53 PM
  5. validate hex character
    By paul in forum New To Java
    Replies: 1
    Last Post: 07-25-2007, 09:08 PM

Posting Permissions

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