Question

i am Using DisplayTag table library to render my tables, which gives the option to specify messageFormat patterns for the data. i am having some hard time in finding the correct format's following are the formats i am trying to write

  1. given a double print its currency representation without decimal points e.g 25.25 as $25 

  2. if a negative double is given it must print -$25 currently its printing ($25)
  3. if double is 0.00 the it should not be printed
Was it helpful?

Solution

The pattern "\u00A4#;-\u00A4#" satisfies your first two requirements. The third one, AFAIK, can't be satisfied with a simple pattern.

You could use a simple amount.tag file doing the following:

<c:if test="${value != 0}>
    <fmt:formatNumber value="${value}" pattern="\u00A4#;-\u00A4#"/>
</c:if>

Note that not displaying anything for 0 is a bit strange, since any value between 0 and 0.5 will display as $0 due to rounding anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top