-1

Possible Duplicate:
Using double up to two decimal places

Hi i want to convert double value upto 6 point something like if value is

  -1.00005522000

it should be converted and resulted into

  -1.000055

i know there are lots of solution but still i could not getting the value

if i use value like

  : -1.79769313486231E308

the resulted value become

  -9.22337203668547

i have used reference like

http://www.roseindia.net/java/beginners/RoundTwoDecimalPlaces.shtml

How to print upto two decimal places in java using string builder?

Using double up to two decimal places

but do not get solution so please any body can help me?

Community
  • 1
  • 1
Siddhpura Amit
  • 14,534
  • 16
  • 91
  • 150

3 Answers3

6

use decimal format.

DecimalFormat df = new DecimalFormat("#.######");
df.format(1.00005522000);

for more information click here

Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • DecimalFormat df = new DecimalFormat("#.######"); txtAlt.setText(df.format(getInfo.getDoubleExtra("alt", 0))); but still get 09-10 12:36:44.199: I/System.out(3611): Double Value is : -179769313486231000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 – Siddhpura Amit Sep 10 '12 at 07:14
3
double d = 1.00005522000;
String result = String.format("%.6f", d);
Ted Hopp
  • 232,168
  • 48
  • 399
  • 521
  • I have used this way also but do not know still not getting value – Siddhpura Amit Sep 10 '12 at 07:30
  • 1
    Do you want to format your double value to 6 decimal points as a String, or do you want a double value that is the result of rounding another double? If you want the latter, then you should use something like `BigDecimal`. A `double` generally cannot represent any specific fractional number exactly. (A number that terminates in base 10 often does not terminate in base 2.) – Ted Hopp Sep 10 '12 at 08:09
-1
string str=1.00005522000;
sting[] newstr=str.split(".");
newstr[0];//contains 1
newstr[1];//contains 00005522000
newstr[1].substring[0,5];//it contains  6 numbers
SreeRanga
  • 49
  • 3