Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Decimals in BigDecimal output  RSS feed

 
Johannes barberaren
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have a problem which is probably easy to solve but I have googled some without finding it.

I have a BigDecimal in my source files which I call from an xhtml file like this:


<h:outputText value="#{someBean.someVariable} "></h:outputText>


This variable can have any number of decimals but I would like it to be outputed with 2 decimals.

Is there an easy solution?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Johannes!

The "f:formatNumber" tag does this. At least it does for floating-point numbers, and therefore it's reasonable to expect that it works on BigDecimal values as well.

The formatnumber element should be coded as a child element under the outputText element.
 
Johannes barberaren
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:Welcome to the JavaRanch, Johannes!

The "f:formatNumber" tag does this. At least it does for floating-point numbers, and therefore it's reasonable to expect that it works on BigDecimal values as well.

The formatnumber element should be coded as a child element under the outputText element.



Thank you for your reply.
Unfortunately I don't know how to use f:formatnumber exactly.
I tried to google for " f:formatNumber jsf" But I didnt get a single relevant hit as far as I could tell?
Is there an example of this by any chance somewhere?

Regards
/Johannes
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I always get the name wrong. It's convertNumber, not formatNumber. Sorry.
 
Johannes barberaren
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello thanks for the reply again, it wasn't as simple as all that however but it got me on the right path.
I had to create my own converser in the end.

If someone else reading this have the same problem some day here are 2 links that helped me out:

http://lucamolteni.wordpress.com/2010/07/23/using-bigdecimals-in-jsf/
http://www.javabeat.net/articles/53-using-converters-in-jsf-3.html



/Johannes
 
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!