This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how to avoid -e exponential representation in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to avoid -e exponential representation in servlet" Watch "how to avoid -e exponential representation in servlet" New topic
Author

how to avoid -e exponential representation in servlet

sakthi vadivel
Ranch Hand

Joined: Dec 16, 2007
Posts: 44
hi ranch.

Anybody tell me the API to convert exponential number to ordinary number in servlet.

thanks in advance.
sakthi


sakthi SCJP, SCWCD OCA
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
(Moved to a more general forum, since the answer has nothing to do with servlets.)

What do you mean by "convert" - what data type and format does the input have, and what data type and format should the output have? Integer? String? Something else? Can you give an example of input and desired output?
sakthi vadivel
Ranch Hand

Joined: Dec 16, 2007
Posts: 44
sorry i forget to mention that...

I want to display the double value without exponential representation. whether string or long or double....
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15000
    
  27

Use a DecimalFormat object to convert your double to a String:

Lookup the documentation for DecimalFormat.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ulf Dittmer
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
Something like the following should do the trick. Be sure to read the javadocs of the toPlainString method.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44550
    
  34
If you know the likely range of the values to display, try the %f tags. They work with the Formatter#format, PrintStream#format, PrintStream#print(ln) and String#format methods.
sakthi vadivel
Ranch Hand

Joined: Dec 16, 2007
Posts: 44
thankyou folks...

i got solution new java.math.BigDecimal(d).toBigInteger()

because toPlainString() is undefined for the BigDecimal....

thanks to all....
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20132
    
  30

I think you need new glasses. toPlainString() is undefined for BigInteger; it is most definitely defined for BigDecimal.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to avoid -e exponential representation in servlet
 
It's not a secret anymore!