Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 26
Registered: ‎08-26-2009
My Device: Not Specified
Accepted Solution

How to convert double to String without scientific notation.

Hello,

 

I am tring to convert a double 24,000,000.00 to String. But I got  a string "2.4E7". 

 

Does anybody knows how can I avoid this scientific notation issue?

 

 

Thanks

Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to convert double to String without scientific notation.

I am not aware of a way to do this.  I don't think there are any generic formatter objects on the BalckBerry platform to help either.

 

 

Developer
Posts: 80
Registered: ‎09-12-2009
My Device: Bold 9700
My Carrier: Vodafone UK

Re: How to convert double to String without scientific notation.

[ Edited ]

Could you paste the code to how you are converting so that I may offer up an alternative?

 

If not what I always do to keep things simple is add something to a blank string ie

 

String doubleString = ""+ doubleValue; 

 

it wont have the formatting of commas and decimal wont be rounded to two digits (i think),

 

someone else may be able to offer up a much better solution, but you could give this a try if you can't come up with anything else

Message Edited by geeneeus on 09-19-2009 11:59 PM
Genius Development Scotland
Website: http://www.genius-dev.co.uk
Developer
Posts: 905
Registered: ‎02-07-2009
My Device: BlackBerry Torch 9800
My Carrier: Globe Telecom

Re: How to convert double to String without scientific notation.

use Double.toString(double)
Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to convert double to String without scientific notation.

Sorry johnbibs, I think you missed the first post in this Thread.

 

If you do something like

 

double d = 24000000.00d;
String sd = Double.toString(d);

 

you will get a String in Exponential format, "2.4E7" in this case, but the OP wants it fully spelt out.

New Developer
Posts: 3
Registered: ‎09-20-2009
My Device: Not Specified

Re: How to convert double to String without scientific notation.

Have you tried casting to an int?  something like:

 

double d = 24000000.0;

int i = (int)d;

String s="" + i;

 

Then just add the remainder to your string to get the precision that you would want...

 

double remainder = d - i;

remainder = remainder*100;

 

s+= "." + (int)remainder;

 

You would lose a little precision due to rounding problems, but you could use the rounding functions in the api to get a closer answer.  

Developer
Posts: 26
Registered: ‎08-26-2009
My Device: Not Specified

Re: How to convert double to String without scientific notation.

Nice solution. Thanks a lot
Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to convert double to String without scientific notation.

Of course, this solution assumes that the significant value of the double is within the bounds of an Integer value...
Developer
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: How to convert double to String without scientific notation.

Hi Peter

 

I have doubt about balckberry browser . i will give thread link for you

 

can you please help me..

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=61336

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Developer
Posts: 19,624
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to convert double to String without scientific notation.

@ kumaresan - hijacking another Thread is extremely impolite, probably worse than the impatience I suggested you were showing when I responded to your Thread earlier.

 

Can I suggest that you review the following:

 

http://www.catb.org/~esr/faqs/smart-questions.html

 

It will give some hints as to the best ways to use forums like this.  And please don't post an apology on this Thread - just don't do it again!