How to format a Float Value with the device currency format?

后端 未结 4 1958
执念已碎
执念已碎 2021-01-31 07:30

I have an app that prints a calculated money value and I want to display that value with the default currency format.

For example in Europe you would write:

1.

4条回答
  •  一向
    一向 (楼主)
    2021-01-31 08:00

    I found the solution. THe class NumberFormat has a multitude of predefined formatters. There is also one for formatting currency Values.

    If you use the static method getCurrencyInstance the class will return a formatter for the device default currency. I use the following code to set my result:

    NumberFormat format = NumberFormat.getCurrencyInstance();
    ((TextView) findViewById(R.id.text_result)).setText(format.format(result));
    

提交回复
热议问题