user852508
user852508

Reputation: 1

String.format gives `,` instead of `.`

String.format("%.2f",0.333333); gives 0,33 but I'd like to have 0.33.

Upvotes: 0

Views: 257

Answers (2)

Apps Maven
Apps Maven

Reputation: 1420

String.format() picks the locale you are in. You have to specify the locale explicitly if you want. instead of,

You can use it like this:

String.format(Locale.US, "%.2f", 0.333333)

Upvotes: 0

Patrick
Patrick

Reputation: 11

Put Locale.ROOT inside, like this:

String.format(Locale.ROOT, "%.2f",0.333333);

Upvotes: 1

Related Questions