# Thread: Inputting Decimal Value

1. Member
Join Date
Dec 2013
Posts
4
Rep Power
0

## Inputting Decimal Value

Was been searching around the net and I can't find a concrete answer or probably it is hard to understand those stuffs I saw.

So yeah, we have an activity and here is what I need to know;

- Write the appropriate Java statement to match the description in each of the following comments:
• //declare an integer variable for the cost of an item
• // declare a double variable for the sales tax percentage
• // prompt the user for the item cost
• // input the item cost
• // prompt the user for the sales tax percentage
• // input the sales tax percentage
• // output the amount of sales tax owed on the item, found by multiplying the item cost by the sales tax percentage

From what I've understand, here is what I made:
Java Code:
```import java.util.*;
import java.io.*;
import java.lang.*;
class wew2{
public static void main(String [] args){

Scanner x = new Scanner(System.in);

int cost;
final double stp;

System.out.print("Enter Item Cost: ");
cost = x.nextInt();

System.out.print("Enter Sales Tax Percentage: ");
stp = x.nextDouble();

double sto = (cost * stp);

System.out.println("Sales Tax Owed: "+sto);

}}```
BUT... I'm having this error:
Java Code:
```Exception in thread "main" java.util.InputMismatchException
at java.utilScanner.throwFor(Unknown Source)
at java.utilScanner.next(Unknown Source)
at java.utilScanner.nextDouble(Unknown Source)
at wew2.main(wew2.java:16)```
I've been researching everywhere on how can I input a decimal value in the STP since it is asking for the tax percentage, since it is asking for the tax percentage... you have to convert the percentage into (EX. 10% = *0.10).

How to do this?

Operating System: Windows 8.1 Pro 64bit
Java Version: 7.0.450.18 (64bit)
Editor: Crimson Editor
Last edited by Mind Blown; 12-04-2013 at 05:15 PM.

2. ## Re: Inputting Decimal Value

You did type an integer number for the item cost, did you?

kind regards,

Jos

3. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Inputting Decimal Value

Its complaining about the nextDouble(), so on the input of the tax. Looks like this is the good old "newline still in the character stream" problem that passed by at least a few times a week.

4. Member
Join Date
Dec 2013
Posts
4
Rep Power
0

## Re: Inputting Decimal Value

Ok, I found out the solution.

I just found out that the system language/region of my Windows is Swedish/Sweden, wherein our decimal is komma (,) not period (.) (my tutor has an English US region Windows).
It was a huge fail of me not figuring it out and not realizing it the first place after trying and trying again and again in 3 whole hrs.

Right now, all I did was... changed my system language/region to English (US).

Posting the solution for those who don't know.
Anyways, thanks guys and sorry for my stupidity.

5. Moderator
Join Date
Apr 2009
Posts
13,369
Rep Power
24

## Re: Inputting Decimal Value

Originally Posted by gimbal2
Its complaining about the nextDouble(), so on the input of the tax. Looks like this is the good old "newline still in the character stream" problem that passed by at least a few times a week.
It wouldn't be (well, it isn't based on the follow up post).
That only occurs when you mix in nextLine() calls with the other nextXXX() calls.
nextLine() is the odd one out, in that it doesn't discard a leading token in the buffer, it reads up to a token.

6. ## Re: Inputting Decimal Value

Originally Posted by gimbal2
Its complaining about the nextDouble(), so on the input of the tax. Looks like this is the good old "newline still in the character stream" problem that passed by at least a few times a week.
No it isn't: new line characters are considered white space; I ran the code and it ran fine ...

kind regards,

Jos

7. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: Inputting Decimal Value

Alright, I learned something. I never use the Scanner class myself :)

#### Posting Permissions

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