I'm trying to learn java for AP computer science A and thought I would try to make a simple remainder calculator. This calculator prompts the user to enter a number and it will give the remainder when divided by 1 (it's not a good calculator).
Here is my program:
public class Unit2Lab2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
float Value = scanner.nextFloat();
float a = Value % 1;
System.out.println(a);
}
}
It was all fine and dandy but when I tested it out by plugging in the value of 15.98, the result I got was 0.999999976. I don't know why this happened but I managed to circumvent the issue by using the df.format command I found online.
I still want to know if there is a way to stop the remainder function from getting wonky.