Format Int Variable in R$ currency on Android

Asked

Viewed 1,206 times

-1

I use Maskformatter lib to format Edittext fields. But now I’m getting a value of an int variable and wanted to format it in the value of currency R$.

Example: in the variable containing 1000 Format: 10,00

Using lib I can’t because it only accepts Edittext.

I am using the result of this variable and displaying in a Textview.

  • 1

    A variable containing 1000 (thousand) would be correct to format: R$ 1000,00 right?

  • @Laerte as in the example, let’s assume that in the variable the value was thirty-four real. But in my textview it is displaying 3400. Formatting would like him to put the comma, getting 34.00.

1 answer

0

Good I managed to settle after a good read

I used

NumberFormat nf = NumberFormat.getCurrencyInstance();

and in the Textview variable

nf.format(valortotal / 100)

result in what I really wanted R$34,00 ou R$10,00

From what I understand using the NumberFormat.getCurrencyInstance() it takes system formatting, either BR or EN.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.