Hi
Is there a way that I can convert the following to double. The scenario is if my
string starts with 16# and ends with # I have to take the value in between 16# and # as hexadecimal and then convert it to double e.g. the string value is :
String s = "16#1234#";
Now if I convert this to long I am doing this
if (s.startsWith("16#") && s.endsWith("#"))
{
extractedValue = s.substring( 3, s.length()-1 );
longValue = Long.parseLong( extractedValue, 16 );
}
I am using the radix as 16 because of the condition defined above. Luckily there is method
parseLong(String s, int radix)
in java.lang.Long. But there is no such method that takes radix also in java.lang.Double
we only have a parseDouble(String).
So is there a way I convert the above string to double treating it as a hexadecimal just like done with parseLong. If I extract the values in between 16# and # I get 1234 and now say do this
double d = Double.parseDouble(1234);
I get different result because it treats 1234 as double though it's hexadecimal value. The same applies to octal and others. Is there a way or work arround this.
I really appreciate for any help.
Thanks