0

I have BigDecimal property in model. Is's storing money value . Now i want to show money in 123 456 789,00 format.

i want to do it in view part of application. I am using Spring framework.

what is a best practise to do it?

AEMLoviji
  • 3,217
  • 9
  • 37
  • 61

2 Answers2

1

The best way to format money value in the JSP view is to use JSTLs.

For example:

<fmt:formatNumber currencySymbol="$" type="number" maxIntegerDigits="2" value="${balance}" />

In your case you may have to set a different pattern (to display the space after each 3 numbers)

http://www.tutorialspoint.com/jsp/jstl_format_formatnumber_tag.htm

ianaz
  • 2,490
  • 3
  • 28
  • 37
  • i am still using – AEMLoviji Feb 18 '14 at 10:10
  • mmh... seems that you can't do it directly with jstl :( here is another dirty option: http://stackoverflow.com/questions/15087544/can-jstl-fmtformatnumber-be-used-to-get-this-output-1-234-56 or you can create your own tag – ianaz Feb 18 '14 at 10:31
0

if you are working with jsf you can use

<h:outputText id="balance" value="#{accountBean.balance}">
    <f:convertNumber currencySymbol="$" groupingUsed="true"
                     maxFractionDigits="2" type="currency" />
</h:outputText>

jsfToolBox converNumber

Another example specifiying locale:

<h:outputText value="#{llistaV.importTotal}"rendered="#{llistaV.importTotal != null}">
 <f:convertNumber currencySymbol="$" maxFractionDigits="2" type="currency" locale="es-ES"/>
    <!-- pattern="###,###.###$" -->
</h:outputText>
ZaoTaoBao
  • 2,567
  • 2
  • 20
  • 28