0

I've got a input in my program expecting a double:

Scanner in_num = new Scanner(System.in);
double num1 = in_num.nextDouble();

but in the uploading system it throws exception java.util.InputMismatchException and I found out that it's because of the system writing a dot as a decimal point.

Is there a way in Java to take a number with a dot as a decimal point instead of comma?

2 Answers2

1
  1. Switch your Scanner into US Locale:

    Scanner sc = new Scanner(System.in);
    sc.useLocale(Locale.US);
    double d = sc.nextDouble();

  2. Use Double.parseDouble():

    BufferedReader reader = new BufferedReader(new inputStreamReader(System.in));
    double d = Double.parseDouble(reader.readLine());

user
  • 33
  • 5
0

I found solution, just had to think a little bit. I've just taken a next String and parsed it to Double.

double num1 = Double.parseDouble(in_num.next());