File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BigDecimal in EL addess scales

 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to generate a report that has several floating values.

In order to get it precise, I used BigDecimal for all the variables.

I found out that EL in jsp would use A.multiply(B) when saying something like:



and both A and B are BigDecimal

The problem is that A.multiply(B) means that the scales will be added. So, if A has a scale of 2 and B has a scale of 2 I will get a scale of 4 !

So if A = 2.00 and B = 3.00 and I do ${A*B} i'll get 6.0000

Is there any way I can get only 6.00, I want exactly the same decimal places (two) not more not less

Thanks,
[ March 15, 2008: Message edited by: Bear Bibeault ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest creating a JavaBean to handle these operations and putting the bean in request scope. For example, you could have a MyData bean with a getAMultB() method that returns a BigDecimal with the correct scope. In your jsp, you'd use the expression ${MyBean.aMultB}.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or check out the <fmt:formatNumber> action.
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Merrill,

It sounds like a good idea but,
I'm going to need to set the values in the bean itself

so if I have variables A and B I'd have to set some bean properties

like



and then retreive the bean

won't that increase the amount of code as I have to substitute 1 line for 3 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<cricket> <cricket> <cricket>
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,

Can you help me out...I think I got your idea about numberFormat, can you show me a sample...everytime I do this:

<fmt:formatNumber value="${factor *1} />

I get an error that this taglib doesnot accept expressions
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ali Khalfan:
I get an error that this taglib doesnot accept expressions
That is usually an indication that you are using the wrong JSTL version for the version of JSP that you are using.

What container are you using? (forum instructions dictate that you should have already supplied this info)
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i sincerely apologize.

I'm using nebeans 5.5, java 6 and JSTL 1.1
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gee, you kinda told me everything except what I need to know. Netbeans is your IDE, not your container. I imagine you're using some version of Tomcat. Which one?

If it's Tomcat 5 or 6, you should make sure to set your web.xml up as outlined in the JSP FAQ to enable Servlets 2.4 and JSP 2.0, and then be sure that you are using the correct URIs for JSTL 1.1.
[ March 15, 2008: Message edited by: Bear Bibeault ]
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry, I don't know what's gotten into me these days, I'm not able to think right.

It's tomcat 5..i'll check the FAQ
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure to check your JSTL URIs as well. The error you are getting usually crops up when you use JSTL 1.0 URIs with JSP 2 or vice versa.
[ March 15, 2008: Message edited by: Bear Bibeault ]
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works good and the night is young

thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic