Netbeans using comma as default. Why?

时光怂恿深爱的人放手 提交于 2021-02-10 20:26:15

问题


Hello guys and girls, So, Netbeans (like most IDE's) use dots (.) to organize decimal places, right? I dont know why but my IDE began to use comma (,) to organize decimal places... even the outputs showed in the console are using commas. How can i change it back to default settings and start using dot in decimal places again?

PS: When i try to enter a number using dot and the decimal places (4.5, for example) i get this error message:

Exception in thread "main" java.util.InputMismatchException
    at java.base/java.util.Scanner.throwFor(Scanner.java:939)
    at java.base/java.util.Scanner.next(Scanner.java:1594)
    at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
    at EstruturasDeControle.If.main(If.java:16)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
    at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
    at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

回答1:


Scanning input which expects a comma rather than a period as the separator for decimal values (or vice versa) is directly related to the Locale being used.

There are three ways of specifying the Locale to resolve your problem:

  1. You can specify the locale to be used by default as a parameter when NetBeans is started:

    --locale <language[:country[:variant]]>

    For example: --locale en:US for American English, and --locale fr:FR for French.

    This setting will apply for the current NetBeans session only.

  2. You can permanently set the default locale used by NetBeans, by specifying it in the file etc/netbeans.conf within your NetBeans installation directory:

    • Open that file in any text editor.
    • Locate the line containing the text netbeans_default_options
    • Add the values to specify the language and country of the locale. for example, to set the locale to US English: -J-Duser.language=en -J-Duser.country=US
    • See the article Change UI language to English on Netbeans IDE for more details.
  3. You can dynamically specify the Locale to be used at the application level within the code. For example, in your case you could set the locale used by your application's Scanner by calling useLocale().

Your code code might look like this:

Scanner scanner = new Scanner(System.in);
scanner.useLocale(Locale.US); // US locale, so period is expected for numeric input.
...
scanner.useLocale(Locale.FR); // France locale, so comma is expected for numeric input.

All three approaches can resolve your problem, and you can use any or all of them. Your specific needs determine the one(s) to be used.



来源:https://stackoverflow.com/questions/58457466/netbeans-using-comma-as-default-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!