I have a BigDecimal
field amount
which represents money, and I need to print its value in the browser in a format like $123.00
, $15.50
, $0.33
.
How can I do that?
(The only simple solution which I see myself is getting floatValue
from BigDecimal
and then using NumberFormat
to make two-digit precision for the fraction part).
Money
type, which has the amount, the currency, and the precision. Then, you only need a ratio (which would probably be aBigDecimal
or something similar) to convert from one currency to the other. Within theMoney
type, you would of course use fixed point. Using fixed point sounds too much like doing your own time calculations for my liking. – LigniformBigDecimal
is not floating-point. It is decidedly fixed-point.float
is floating-point. It is rarely a good idea to convert between them. – Digression