This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 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: 41085
    
  43
(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: 14074
    
  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: 41085
    
  43
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: 37950
    
  22
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: 19651
    
  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
 
 
subject: how to avoid -e exponential representation in servlet
 
Similar Threads
Big O Notation
assignment 2.2
double primitive in two forms
Changing the exponential number into normal readable number format?
Need help on Shift operators