0

I'm new to java and I would like to know how to multiply a "double" by a fraction. I want to calculate the taxes on a salary (in France). I have tried :

       import java.util.Scanner;
       class Main {
       public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
          System.out.println("Quel est votre salaire brut annuel ?");
          double salaireBrut = sc.nextDouble();
          double salaireNet = salaireBrut;
          if (9710 < salaireBrut && salaireBrut <= 26818) {
          salaireNet = salaireBrut * (86 / 100);
          }
          System.out.prinln(salaireNet);
       }
       }

So it outputs 0.0 instead of salaireBrut * (86 / 100). Can you guide me on what to change, please ? Thank you in advance.

  • Change to `86.0/100` or `100.0/86`. – Kayaman Jan 30 '18 at 20:12
  • actually just removing the parentheses should fix it. – khachik Jan 30 '18 at 20:14
  • Thank you so much guys, you are legit my saviours. I love you so much. Have a nice day. – I can't find a Channel name Jan 30 '18 at 20:16
  • By the way, in real work you would never use `double` or `Double` for salary or anything else monetary. Those data types use [floating-point technology](https://en.wikipedia.org/wiki/Floating-point_arithmetic) that trades away accuracy for speed of execution. When accuracy matters more than speed, use [`BigDecimal`](https://docs.oracle.com/javase/9/docs/api/java/math/BigDecimal.html). – Basil Bourque Jan 30 '18 at 20:42

0 Answers0