Java – How to return a formatted number via String.format?

How to return a formatted number via String.format?… here is a solution to the problem.

How to return a formatted number via String.format?

When I use the String.format method, if my phone language is Farsi, this method returns a number in Farsi format. But I want to use numbers in English format.
I use this code:

String.format("%.02f", myNumber)

My question in the picture:

enter image description here

Solution

I think you need to use String.format(Locale, String, ...) Methods with English instances of locale, possibly with locale.ENGLISH. This tells String.format to use English number format instead of Farsi.

Related Problems and Solutions