File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 41
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
Marshal

Joined: Mar 22, 2005
Posts: 41600
    
  55
(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?


Ping & DNS - my free Android networking tools app
sakthi vadivel
Ranch Hand

Joined: Dec 16, 2007
Posts: 41
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: 14114
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41600
    
  55
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: 38481
    
  23
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: 41
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: 19680
    
  18

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
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