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!

Getting double object from String

807606Apr 18 2007 — edited Apr 19 2007
Hi,

I am trying to get double object from strings like

1) 3.30E03 ==> This works
2) 3.30E3 ==> This works
3) 3.30E-03 ==> This works
4) 3.30e-03 ==> This does not work. Something to do with lower case.
5) 3.30E+3 ==> This does not work. Output is 3.3 instead of 3,300 (in English Locale)

I am using following code to get java double object from string.

/**
public static Double convertLSDoubleToJO( String doubleValue,
Locale inputLoc ) throws ParseException
{
Double d = null;
NumberFormat nf = NumberFormat.getInstance( inputLoc );
nf.setMinimumIntegerDigits(100);
nf.setMaximumIntegerDigits(100);
nf.setMinimumFractionDigits(100);
nf.setMaximumFractionDigits(100);
String decPattern = df.toPattern();
DecimalFormat decFor = null;
if ( nf instanceof DecimalFormat )
{
decFor = (DecimalFormat) nf;
decFor.applyPattern( decPattern );
}
double doublePrimitiveType = decFor.parse( doubleValue ).doubleValue();
d = new Double( doublePrimitiveType );
return d;

}
**/

I am using java 1.4.2
Any ideas how can i parse strings as mentioned in case 5 above.
Thanks in advance.

Regards,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2007
Added on Apr 18 2007
3 comments
96 views