M
Mel
Hi,
I have a tricky decimal separator problem in java 1.2
When calling
Double.valueOf("2.5");
everything is fine but on the second machine thios version
Double.valueOf("2,5");
is correct.
Obviously I have to consider localization settings.
My first approach was to use the localized decimal separator
char chDec = new DecimalFormatSymbols().getDecimalSeparator();
String ret = "2.5";
char chDec = new DecimalFormatSymbols().getDecimalSeparator();
if(chDec != ',') ret = ret.replace(',', chDec);
if(chDec != '.') ret = ret.replace('.', chDec);
Double.valueOf(ret);
To my surprise this didn't work too because my machine can read
Double.valueOf("2.5");
but the localised version looks like this
Double.valueOf("2,5");
To get rid of the localisation settings I tried this version
DecimalFormat df = new DecimalFormat();
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.');
df.setDecimalFormatSymbols(dfs);
return df.parse(StrEnforceDecimalDot(strVal)).doubleValue();
This works fine on one machine but not on the other. Is there something
wrong with the code.
Machine 1 looks like this:
WinXp German version -> Oracle9iRel2 -> Java running within Oracle
Machine 1 looks like this:
Unix -> Oracle9iRel2 -> Java running within Oracle
What am I missing?
Which strings can Double.valueOf parse per definition.
I can't find a clear specification in the java doc.
Do I have to consider Oracle NLS parameters?
Thanks for any help.
Mel
I have a tricky decimal separator problem in java 1.2
When calling
Double.valueOf("2.5");
everything is fine but on the second machine thios version
Double.valueOf("2,5");
is correct.
Obviously I have to consider localization settings.
My first approach was to use the localized decimal separator
char chDec = new DecimalFormatSymbols().getDecimalSeparator();
String ret = "2.5";
char chDec = new DecimalFormatSymbols().getDecimalSeparator();
if(chDec != ',') ret = ret.replace(',', chDec);
if(chDec != '.') ret = ret.replace('.', chDec);
Double.valueOf(ret);
To my surprise this didn't work too because my machine can read
Double.valueOf("2.5");
but the localised version looks like this
Double.valueOf("2,5");
To get rid of the localisation settings I tried this version
DecimalFormat df = new DecimalFormat();
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('.');
df.setDecimalFormatSymbols(dfs);
return df.parse(StrEnforceDecimalDot(strVal)).doubleValue();
This works fine on one machine but not on the other. Is there something
wrong with the code.
Machine 1 looks like this:
WinXp German version -> Oracle9iRel2 -> Java running within Oracle
Machine 1 looks like this:
Unix -> Oracle9iRel2 -> Java running within Oracle
What am I missing?
Which strings can Double.valueOf parse per definition.
I can't find a clear specification in the java doc.
Do I have to consider Oracle NLS parameters?
Thanks for any help.
Mel