0

i'm preforming a calculation (converting gigabytes to bytes) but i'm not get the expected results..i believe the calculations and logic is correct but i think it's the way i'm storing my number. i've played with using int, double, float and can't get the right format. i've set the text using toString, valueOf and String.format.

i'm getting 1.0737418E9 instead of 1073741824

relative code below: Thanks!

double sumB;
double sumG;

// get values 
Bytes = (EditText)findViewById(R.id.numBytes);
Gigs = (EditText)findViewById(R.id.numGigs);


//calculations
   sumB = Double.parseDouble(Gigs.getText().toString()) * 1073741824; //couldn'f figure out how to use exponents
   sumG = Double.parseDouble(Gigs.getText().toString()) * 1;

//set text
  //Bytes.setText(Integer.toString(sumB));  
               // Bytes.setText(Double.toString(sumB));  //didnt work
               // Bytes.setText(String.format("%.8s", sumB)); //didnt work
                Bytes.setText(String.valueOf(sumB));   
                Gigs.setText(Double.toString(sumG));
branedge
  • 115
  • 3
  • 14
  • 1
    try to change `Double.parseDouble();` to `Double.valueOf();`, and `Gigs.setText(String.valueOf(sumG));` – Marcelo Ferracin Mar 30 '17 at 14:09
  • sorry i get the same results – branedge Mar 30 '17 at 14:16
  • 1
    Probably this is related to your problem http://stackoverflow.com/questions/20813631/how-to-avoid-scientific-notation-in-double – Mike Holtkamp Mar 30 '17 at 14:36
  • 1
    The differences between the two results could be the result of output formatting choices. I suggest using identical double-to-string conversion methods, and possibly using DecimalFormat to control the formatting. – Patricia Shanahan Mar 30 '17 at 14:50
  • Thanks guys..not sure which one to mark as the answer.. i set the calculation up like this: sumB = Double.valueOf(Gigs.getText().toString()) * 1073741824; and the setText to this DecimalFormat df = new DecimalFormat("#.#######"); Bytes.setText(df.format(Double.valueOf(sumB))); – branedge Mar 30 '17 at 15:14

0 Answers0