The Artima Developer Community
Sponsored Link

Java Answers Forum
double without the exponent

6 replies on 1 page. Most recent reply: Oct 16, 2003 4:16 AM by Alex S

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
patoots

Posts: 6
Nickname: patoots
Registered: Oct, 2003

double without the exponent Posted: Oct 13, 2003 6:44 PM
Reply to this message Reply
Advertisement
Hi! Have a prob.

What happens is that... when I have a value of

String tempNum = 123456789012.12

...and when i convert the variable (tempNum) to a double:

double doubleNum = Double.parseDouble(tempNum);

the result of doubleNum = 1.2345678901212E11.

Just like to ask if there's a possibility that you take away the E(exponent) in a value whose datatype is of double and still get the same value 1234567890.12 which is numeric? Or should I not use double if i want to reach that result?

Thanks! This would be of great help!

patoots


Alex S

Posts: 27
Nickname: andu
Registered: Mar, 2003

Re: double without the exponent Posted: Oct 13, 2003 11:16 PM
Reply to this message Reply
If you have decimal numbers, you can store them in a long or double variable.

And if you want to display them, you can use the DecimalFormat class to remove your exponent.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: double without the exponent Posted: Oct 14, 2003 12:13 AM
Reply to this message Reply
The fact that you are converting String to double means that you are planning to use it in some calculations???

If yes do you expect exact results from those calculations?

If yes double might not be suitable and you might want to look into BigDecimal class.

Senthoor

patoots

Posts: 6
Nickname: patoots
Registered: Oct, 2003

Re: double without the exponent Posted: Oct 15, 2003 6:06 PM
Reply to this message Reply
Senthoor: no, am not doing any calculations... am doing this because am manipulating the value for display purposes. What i wanna do is if I initialize the string variable with the said value and convert/parse it to double, i'd still get the same value... without the E in the value.

Maybe I'll try using BigDecimal and do some manipulations with it. Unless you can give me simpler options ;)

Thanks!

patoots

Posts: 6
Nickname: patoots
Registered: Oct, 2003

Re: double without the exponent Posted: Oct 15, 2003 6:19 PM
Reply to this message Reply
Alex S: if I use long, the value would lose its precision... i still need the whole value with the decimal point.

Hmmm... interesting... I haven't used the DecimalFormat class... i'll try that one too :) super thanks!

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: double without the exponent Posted: Oct 15, 2003 8:10 PM
Reply to this message Reply
I think the simpler solution is for you go with DecimalFormat class

Alex S

Posts: 27
Nickname: andu
Registered: Mar, 2003

Re: double without the exponent Posted: Oct 16, 2003 4:16 AM
Reply to this message Reply
Read float not long!

Mea culpa.

Flat View: This topic has 6 replies on 1 page
Topic: error in the JSP page. Previous Topic   Next Topic Topic: First ->Second->Thrid->... of EJB

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use