• 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

Present Double in non scientific notation

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I run an xml application on Tomcat, using jelly.
I have a variable that is a double. I want to present it with 4 decimals, however, when the value gets too small, ie. 0.0001, it shows the scientific notation.
Does anybody know how to solve this is?

thanks in advance
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out DecimalFormat
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Todd Buell wrote:Check out DecimalFormat

. . . or printf(), and look in Formatter for the full list of tags. Look particularly at those suitable for floating-point numbers, eg %g.

And welcome to JavaRanch
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Todd Buell wrote:Check out DecimalFormat

By the way, why are you still linking to J2SE1.4.2?
 
Todd Buell
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Todd Buell wrote:Check out DecimalFormat

By the way, why are you still linking to J2SE1.4.2?



Sorry about that. Just used the first link from a search using Google. I will update the original link.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. It is odd that Google should give you a link to 7-year old websites. Of course there are still people who use old versions of Java.
 
sowi so
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!

DecimalFormat looks promissing, but I don't know how to create an object of it's kind in jelly and use it.
any help is welcome, here's my best shot so far:

<c:new var='sdec' className='java.text.DecimalFormat'>#.####</c:new>
<c:invoke var='dec' method='format' on='${sdec}'>
<c:arg value='${scientific_dec}'/>
</c:invoke>

response is:
"java.lang.IllegalArgumentException: Cannot format given Object as a Number"

greetings
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aha. So this is actually a question about Apache Commons Jelly and not a question about Java. Let's move the post to the corresponding forum...
 
sowi so
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,
where would that be?
and how do I move a post?
thanks
 
sowi so
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it, using:

<c:set var="fmat" value="#.####"/>
<c:new var='dec' className='java.text.DecimalFormat' />
${dec.applyPattern(fmat)}
<c:invoke var='dec1' method='format' on='${dec}'>
<c:arg type="double" value="${double_with_scientific_notation}" />
</c:invoke>

thanks for the help
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic