R
runden-will
Gast
hallo, ich habe folgendes programm erstellt zur übung. nun wollt ich ein wenig rumexperimentieren mit zahlenrunden, und schon hab ich das programm versaut :-/ habe gegoogelt und eine anleitung gefunden die es wie folgt beschreibt (so habe ich es dann auch eingebaut):
hier trotzdem mal das ganze programm zum nachvollziehen:
bin auch dankbar für kritik, falls ich sachen unlogisch gemacht hab oder besser machen könnte.
nochmal zum problem: in visual basic kenne ich so eine rundungsfunktion als
oder auch
oder eben so.
Code:
public float rundeAufZweiStellen(float kontoStand){
return (float) (Math.round( kontoStand * 100 ) / 100.0);
}
hier trotzdem mal das ganze programm zum nachvollziehen:
Code:
import java.lang.Math;
public class Konto_selfmade {
private float kontoStand = 150f;
private String name= "Schmitz";
private static float gebuehren = 3.3f;
/*public void getKontoStand(){
System.out.println("Kontostand: "+kontoStand);
}*/
public void gutschreiben(float betrag){
kontoStand=kontoStand+betrag;
}
public void abheben(float betrag){
kontoStand=kontoStand-betrag;
}
public void abziehenGebuehren(float gebuehren){
kontoStand=kontoStand-(kontoStand/100*gebuehren);
}
public void setName(String name){
this.name=name;
}
public void ausgebenKontodaten(){
System.out.println("Name: "+name+"\nKontostand: "+kontoStand);
}
public float rundeAufZweiStellen(float kontoStand){
return (float) (Math.round( kontoStand * 100 ) / 100.0);
}
public static void main (String[] args){
Konto_selfmade konto = new Konto_selfmade();
konto.gutschreiben(200);
konto.abheben(50);
//konto.getKontoStand();
konto.abziehenGebuehren(gebuehren);
konto.ausgebenKontodaten();
konto.rundeAufZweiStellen(kontoStand);
}
}
nochmal zum problem: in visual basic kenne ich so eine rundungsfunktion als
Code:
Format(Wert,"0")
oder auch
Code:
format(wert,"0.00")