0
Hello, my problem is this: The exercise asks to print several values in Reais. After the tax calculations on top of this value (done on the object) I have toString printing the values, but it prints:
msg += "\n\nTotal Impostos: R$" + totalImpostos() + "\nTotal Mercadorias: R$" + totalMercadorias() +
"\nTotal Geral: R$" + totalGeral;
I wanted these values to be shown in R$ x.xx, at most two decimal places after the point. You have this possibility?
The exercise code was all done by me, so I’m not sure whether I’m right or not.
But if it’s monetary value because you’re using
double
?– Maniero
I really don’t know which format is the right one, I missed classes of primitive types. Should I use float instead? Oh, I will check this question you sent. Thank you
– Gabriel Rabelo Almeida
If the format is in double, if the language of your component is in Brazilian Portuguese, you can use it like this:
NumberFormat.getCurrencyInstance().format( 2 )
, that he already shows just like this:R$ 2,00
– adventistaam