My Code goes as follows:
import java.util.Scanner;
public class MoVerkoopPrijs {
public static void main(String[] args) {
float inkoopPrijs;
final int BTW_HOOG = 21;
final int BTW_LAAG = 6;
double winstMarge;
Scanner in = new Scanner(System.in);
//hieronder wordt je inkoopprijs gevraagd en die moet je dan invoeren
System.out.println("wat is jouw inkoopprijs?");
inkoopPrijs = in.nextFloat();
//hieronder wordt je winstmarge gevraagd en die moet je dan ook invoeren
System.out.println("wat is jouw winstmarge?");
winstMarge = in.nextDouble();
//hieronder zie je de formules hoe je exlusief of inclusief BTW berekend
//hieronder zie je ook wat je moet doen als je de verkoopprijs wilt berekenen.
double winstGetal = (winstMarge / 100);
double verkoopPrijs = inkoopPrijs * (1 + winstGetal);
double inclusiefBtwLaag = (verkoopPrijs / 100) * BTW_LAAG + verkoopPrijs;
double inclusiefBtwHoog = (verkoopPrijs / 100) * BTW_HOOG + verkoopPrijs;
//hieronder print je dan de uiteindelijke prijzen uit
System.out.println("Verkoopprijs exclusief BTW:" + verkoopPrijs );
System.out.println("Verkoopprijs inclusief 6% BTW:" + inclusiefBtwLaag );
System.out.println("Verkoopprijs inclusief 21% BTW:" + inclusiefBtwHoog );
}
}
The current output is:
Verkoopprijs exclusief BTW: 17.726400604248045
Verkoopprijs inclusief 6% BTW: 18.78998464050293
Verkoopprijs inclusief 21% BTW: 21.448944731140134
But the code messes up the last couple decimal places in the output. The actual output for 6% should be: 18.789984000000004
. What is wrong with my code?
I have tried swtiching from float to int and double, but none of them have worked for me.