Question

I get a java.lang.NumberFormatException: For input string: "1.7023484830876092"

trimming the string to 1.70234, does solve the problem, but before slicing the string myself I'm wondering whether its possible to use some java methods to leverage the capacity of the target object.

kind regards, jeroen.

Was it helpful?

Solution

you could try using the DecimalFormat class:

http://download.oracle.com/javase/1.5.0/docs/api/java/text/DecimalFormat.html

  DecimalFormat fm = new DecimalFormat("#.################");
  try {
   double x = fm.parse("1.12345678901234").doubleValue();
   System.out.println(x);
  } catch (ParseException e) {
   e.printStackTrace();
  }

this might work....

OTHER TIPS

It looks like a float. Especially since the first "." is the only one.

Do you perhaps want BigDecimal? It's variably sized to accommodate any number, so long as you have the memory. Use as new BigDecimal(stringNumber). Downside is you don't get access to the standard infix operators(eg. + - * / etc...).

But if you just want the largest value that can be held by a primitive then use Long.MAX_VALUE

You cannot parse floating point values with Long.parseLong. Use Double.parseDouble instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top