Local formatting

Hey!

Doing the Java course, I noticed my machine behaves different from Mosh’s.

System.out.print("Annual interest: ");
float annualInterest = scanner.nextFloat();

This piece of code give me an error if I give it “0.2” ( without quotes). It needs a float with comma… Why? And how can I set my machine (is it the os or the IDE, or …) so that it behaves like I’m in the US.

extra:
Also currency is different. I see the price in Euros. That is not a big problem. I learned that I can set the currency like:

String morgageFormatted = NumberFormat.getCurrencyInstance(Locale.US).format(mortgage);

But again: how can one set currency so that it always be US?

I’m running on MacOS Catalina, IntelliJ 2020.3.2, openjdk15

Thanks, Thom

1 Like

I think both of your issues are caused by the default locale on your system. You can look at the Javadoc for the methods to see how they determine your system locale.

If you are not going to use the system locale you have to specify it like you did in that code block.