Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
//auf zwei Stellen nach dem Komma runden
public double rundeBetrag(double betrag)
{
double round = Math.round(betrag*10000);
round = round / 10000;
round = Math.round(round*1000);
round = round / 1000;
round = Math.round(round*100);
return round / 100;
}
deathbyaclown hat gesagt.:ausgabe geht über das http://java.sun.com/j2se/1.5.0/docs/api/java/text/NumberFormat.html
da kannst du sagen wieviele stellen vor / nach dem komma angezeigt werden sollen
nicht ganz richtig:L-ectron-X hat gesagt.:OK, das schneidet aber nur die Ziffern bis auf zwei Stellen nach dem Komma ab.
Fehlt immer noch die Rundung.
double d1 = 2.3415635634567;
double d2 = 2.3495635634567;
NumberFormat n = NumberFormat.getInstance();
n.setMaximumFractionDigits(2);
System.out.println(n.format(d1));
System.out.println(n.format(d2)););
2,34
2,35
//bmiGerundet = n.format(bmi);
private double BMIBerechnen(){
double groessem, bmi, bmiGerundet;
groessem = groesse / 100;
bmi = gewicht / (groessem * groessem);
NumberFormat n = NumberFormat.getInstance();
n.setMaximumFractionDigits(1); // max. 2 stellen hinter komma
System.out.println(n.format(bmi));
//bmiGerundet = n.format(bmi);
return bmi;
}