I have a fairly simple problem. I am getting real-number input like6.03
, but that gives me errors. If I change it to 6,03
, it's ok. I, however, can't change the input I need to process, so how do I tell Java to use .
as the delimiter instead of ,
?
Scanner sc = new Scanner(System.in);
double gX = sc.nextDouble(); // Getting errors
Thanks
Taken directly from the manual.
Locale-Sensitive Formatting
The preceding example created a DecimalFormat object for the default Locale. If you want a DecimalFormat object for a nondefault Locale, you instantiate a NumberFormat and then cast it to DecimalFormat. Here's an example:
Running the previous code example results in the output that follows. The formatted number, which is in the second column, varies with Locale:
You're probably running into Locale issues. You can use java.text.NumberFormat for parsing.
Scanner
can be provided withLocale
to use, you need to specifyLocale
that uses.
as decimal separator: