Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Currency formatting and color  RSS feed

 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to use JSTL's fmt:formatNumber tag to give a number different color depending on whether the number is positive or negative? I want to make a number red color when it's negative.

Currently I have:

<fmt:formatNumber type="currency" currencySymbol="$" value="${balance}" maxFractionDigits="2" minFractionDigits="2" groupingUsed="true" />

${balance} is a of type String.

What would be the simplest way to give the value different color?

Thanks in advanced.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would do this by changing the CSS class of whatever DOM object is housing your currency information.


 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben.

The balance attribute is a string though. Can I still use >= operator?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would it be a string? I'd change the bean to return a numeric value.
 
Arvind Mahendra
Ranch Hand
Posts: 1162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im new to JSPs in general. Why cant you use some kind of <c:if> thing and have a different font colour?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chunnard Singh II:
Im new to JSPs in general. Why cant you use some kind of <c:if> thing and have a different font colour?
That's pretty much exactly what is going on in Ben's example except that the ternary operator is being used rather than a <c:if>. Since all that is going to be changed is the value of the class attribute, there's no need to for a heavy-weight tag to perform the conditional operation.
[ October 29, 2007: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!