• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BigDecimal in EL addess scales

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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}.
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or check out the <fmt:formatNumber> action.
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<cricket> <cricket> <cricket>
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i sincerely apologize.

I'm using nebeans 5.5, java 6 and JSTL 1.1
 
Bear Bibeault
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
works good and the night is young

thanks
 
Whip out those weird instruments of science and probe away! I think it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic