Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert String to double

807589Nov 11 2008 — edited Nov 11 2008
Hi,

I try to convert string to double like below:
public class StringToDoubleConverter 
{
    public static void main(String args[]) 
    {
        String str = "24855848.98";
        
        //approach 1: to convert String to double
        double d1 = Double.parseDouble(str);
        System.out.println( "d1 = " + d1 );

        //approach 2: to convert String to double
        double d2 = Double.valueOf(str);
        System.out.println( "d2 = " + d2 );
    }	
}   
When i see the output the value is
d1 = 2.485584898E7
d2 = 2.485584898E7

instead of 24855848.98

Please suggest me in this. how do i convert it as it is without this hex value.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 9 2008
Added on Nov 11 2008
7 comments
542 views