Print a double(> than 17 digits) value without E notaion in Java -
i have requirement of printing 22 digit number, when print it, jvm using e notation. have tried bigdecimal class, printf(), string.format(), didn't succeed. accurate till 17 digits, 18th digit data manipulated. example:
original number : 2333333333333333333333 output: 2333333333333333456252
here fragment of code. hope helps
double[] n = new double[t]; for(int i=0;i<t;i++){ n[i] = double.parsedouble(scn.next()); } if(........){ system.out.println(new bigdecimal(n[i]).toplainstring()); system.out.printf("%.0f ", n[i]); }
you're passing in double constructor of bigdecimal causing precision lost. use
system.out.println(new bigdecimal(scn.next()).toplainstring());
Comments
Post a Comment