How do I change acceptance with decimal separator to . instead of , with input in Netbeans IDE 7.0.1?
如何将小数分隔符的接受更改为。而不是在Netbeans IDE 7.0.1中输入?
This is within Netbeans itself like trying this -->
这在Netbeans本身就像尝试这样 - >
System.out.println("Cost?: ");
cost = keyboard.nextDouble();
If this is input with 37.5 following happens -->
如果这是输入37.5以下发生 - >
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextDouble(Scanner.java:2387)
at Lab3_ChangeMoney.main(CostProgram.java:47)
Java Result: 1
But with input 37,5 its ok
但输入37,5可以
I tried via Control Panel, but not
我试过通过控制面板,但没有
1 个解决方案
#1
0
An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the
Locale.getDefault()
method; it may be changed via theuseLocale(java.util.Locale)
method.此类的实例能够扫描标准格式的数字以及扫描程序的语言环境的格式。扫描程序的初始语言环境是Locale.getDefault()方法返回的值;它可以通过useLocale(java.util.Locale)方法进行更改。
So this could be fixed by setting the locale to Locale.US
:
所以这可以通过将语言环境设置为Locale.US来解决:
keyboard.useLocale(Locale.US);
Read more about localized numbers on the manual
阅读手册中有关本地化数字的更多信息
#1
0
An instance of this class is capable of scanning numbers in the standard formats as well as in the formats of the scanner's locale. A scanner's initial locale is the value returned by the
Locale.getDefault()
method; it may be changed via theuseLocale(java.util.Locale)
method.此类的实例能够扫描标准格式的数字以及扫描程序的语言环境的格式。扫描程序的初始语言环境是Locale.getDefault()方法返回的值;它可以通过useLocale(java.util.Locale)方法进行更改。
So this could be fixed by setting the locale to Locale.US
:
所以这可以通过将语言环境设置为Locale.US来解决:
keyboard.useLocale(Locale.US);
Read more about localized numbers on the manual
阅读手册中有关本地化数字的更多信息