Das ist wissenschaftliche Notation.
und Sie bekommen 388 statt 311 da Sie von 1000000 statt 1048576 (1024 * 1024) sind Dividieren
EDIT: 311 noch nicht erreicht man 370 mit 1048576, auf diese Weise bekommen ... so die Fehler ist wahrscheinlich in Ihrem Kalk;)
Als described here, müssen Sie nur Ihre wissenschaftliche Notation in eine Dezimalzahl durch einen Formatierer konvertieren.
DecimalFormat df = new DecimalFormat("#.########");
return df.format(fileLengthMegabytes);
Lauf Beispiel: http://ideone.com/2lkKv7
import java.util.*;
import java.lang.*;
import java.text.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
DecimalFormat df = new DecimalFormat("#.##########");
float fileLengthMegabytes1 = (float) 388/1000000;
float fileLengthMegabytes2 = (float) 388/1048576;
System.out.println("MB1 in Scientific Notation: " +
fileLengthMegabytes1);
System.out.println("MB1 in Decimal Notation: " +
df.format(fileLengthMegabytes1));
System.out.println("MB2 in Scientific Notation: " +
fileLengthMegabytes2);
System.out.println("MB2 in Decimal Notation: " +
df.format(fileLengthMegabytes2));
}
}
Ausgang:
MB1 in wissenschaftlicher Notation: 3.88E-4
MB1 in Dezimal Notation: 0,000388
MB2 in wissenschaftlicher Notation: 3.7002563E-4
MB2 in Dezimal Notation: 0,0003700256
, die ein ganz normales floating ist Punktanzeigetyp. "E" bedeutet "mal 10 hoch", z. "3,88 mal 10 zur Potenz von -4". –
Es sieht so aus, als ob Sie nur wissenschaftliche Notation drucken. Der Wert hat sich nicht geändert. [Java number format] (http://docs.oracle.com/javase/6/docs/api/java/text/NumberFormat.html) –
Wie viele doppelte Antworten brauchen wir? –