This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

BigDecimal in EL addess scales  RSS feed

 
Ranch Hand
Posts: 129
  • 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 ]
 
Ranch Hand
Posts: 4864
  • 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}.
 
Marshal
Posts: 67240
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or check out the <fmt:formatNumber> action.
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 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
Marshal
Posts: 67240
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<cricket> <cricket> <cricket>
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 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
Marshal
Posts: 67240
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
  • 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
Marshal
Posts: 67240
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
  • 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
Marshal
Posts: 67240
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works good and the night is young

thanks
 
Your mind is under my control .... your will is now mine .... read this tiny ad
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!