Ask Experts Questions for FREE Help !
Ask
    GratefulDeadpoo's Avatar
    GratefulDeadpoo Posts: 1, Reputation: 1
    New Member
     
    #1

    May 23, 2016, 03:47 PM
    How can I detect whether an inputted number is in the correct format?
    I'm creating a program where it detects whether an inputted number matches one of the pre-defined formats. Every time I execute my code and input a number, it will say "Invalid input." I'm not sure if it's due to boolean logic or me not using DecimalFormat correctly. Here's the code I have thus far:


    Code:
        do 
    	{
    		System.out.println("Enter the amount you wish to deposit  ==>>  $");
    		amount = inputDW.nextLine();
    		moneyInput = new DecimalFormat (amount);
    		corInput1 = new DecimalFormat ("000.00");
    		corInput2 = new DecimalFormat ("00.00");
    		corInput3 = new DecimalFormat ("0.00");
    		if((moneyInput.equals(corInput1) == false) && (moneyInput.equals(corInput2) == false) && (moneyInput.equals(corInput3) == false))
    		{
    		    System.out.println("Invalid input");
    		}
    	}
    	while((moneyInput.equals(corInput1) == false) && (moneyInput.equals(corInput2) == false) && (moneyInput.equals(corInput3) == false));
    Note: It's obviously only part of my entire code for the program.
    CravenMorhead's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #2

    May 24, 2016, 07:07 AM
    I believe you're using the decimalformat incorrectly. I haven't used this class, let alone java, in more years then I care to think about. The article here suggests that you shouldn't use the constructor. Maybe look at that page and see if it helps.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Correct format of T-account. D on left, C on right but do I add/subtract? [ 1 Answers ]

Please give me the correct format of T-account. I know debits are on left and credits are on right, but do I need to add/subtract anything?

Why does my sleep number bed take up to 10 min to get to correct number? [ 1 Answers ]

The compressor will start and stop over 25 times

I format my loptop and after that wireless cannot detect network even in range [ 3 Answers ]

Myos is windows vista,I downgrade it to windows xp3 sata,after that long instalation my wireless cannot detect network evev in range?I need your pecfect answer right now.thanks in advanced!

The Correct Format For Essay Writing? [ 3 Answers ]

Hello, I am going back to get my G.E.D. after almost 13 years. I need help with learning the approprate way to write an essay. My question: is can anyone give me the line up on how to write an essay? Thank you

Phone number format [ 2 Answers ]

I need to change the format of phone numbers in excel from the standard 000-000-0000 to #10000000000.


View more questions Search