title: My program is having slight precision errors
body: <p>So I'm trying to program a way to solve linear equations in java but when doing math like 24.4-11.6 it has an error where it outputs 12.79 instead of 12.8 here's the code I got, I tried to work around the issue by converting the number to an int by multiplying it by 10000 and the doing the math, after which i divide it by 10000 but in the RtChngX method it seems to be outputting 0 :</p>
  <pre><code>import java.util.Scanner;
  
  public class x_y_intercept_with_2_coords {
  
      public static void main(String[] args) {
    
      System.out.println(&quot;yinter or xinter&quot;);
      Scanner scanner = new Scanner(System.in);
      String interCheck = scanner.nextLine();
      
      
      if(interCheck.equals(&quot;yinter&quot;)) {
      float[] a = new float[2];
      float[] b = new float[2];
      System.out.println(&quot;first x coord&quot;);
      a[0] = scanner.nextFloat();
      System.out.println(&quot;second x coord&quot;);
      a[1] = scanner.nextFloat();
      System.out.println(&quot;first y coord&quot;);
      b[0] = scanner.nextFloat(); 
      System.out.println(&quot;second y coord&quot;);
      b[1] = scanner.nextFloat();
      
      backgroundWrkr one = new backgroundWrkr();
      System.out.println(&quot;yinter = &quot;+one.bWrkrOne(a, b));
      System.out.println(&quot;slope = &quot;+one.getSlope());
      one.rateOfChangeX(a);
      one.rateOfChangeY(b);
          } else {
              float[] a = new float[2];
              float[] b = new float[2];
              System.out.println(&quot;first x coord&quot;);
              a[0] = scanner.nextFloat();
              System.out.println(&quot;second x coord&quot;);
              a[1] = scanner.nextFloat();
              System.out.println(&quot;first y coord&quot;);
              b[0] = scanner.nextFloat(); 
              System.out.println(&quot;second y coord&quot;);
              b[1] = scanner.nextFloat();
              
              backgroundWrkr one = new backgroundWrkr();
              System.out.println(&quot;xinter = &quot;+one.bWrkrTwo(a, b));
              System.out.println(&quot;slope = &quot;+one.getSlope());
          }
      }
  </code></pre>
  
  <pre><code>public class backgroundWrkr {
  
      float slope;
      float rtChngX;
      float rtChngY;
          backgroundWrkr(){
              
          }
          public float bWrkrOne(float[] a, float[] b) {
              float xslope = a[1]-a[0];
              float yslope = b[1]-b[0];
              slope = yslope/xslope;
              float yinter = b[0]-slope*a[0];
              return yinter;
              
          }
            
          public float bWrkrTwo(float a[], float b[]) {
              float xslope = a[1]-a[0];
              float yslope = b[1]-b[0];
              slope = yslope/xslope;
              float yinter = b[0]-slope*a[0];
              float xinter = yinter*-1/slope;
              
              return xinter;
              
          }
          
          public float getSlope() {
              return slope;
          }
          public void rateOfChangeX(float a[]) {
          float gaeA = a[1]*1000;
          System.out.println(gaeA);
          float gaeB = a[0]*1000;
          System.out.println(gaeB);
          int GaeA = (int)gaeA;
          System.out.println(GaeA);
          int GaeB = (int)gaeB;
          System.out.println(GaeB);
          float temp = GaeA-GaeB;
          System.out.println(temp);
          rtChngY = temp/1000;
          System.out.println(&quot;rtChngX = &quot;+rtChngX);   
          }
          public void rateOfChangeY(float b[]) {
          float gaeA = b[1]*10000;
          float gaeB = b[0]*10000;
          int GaeA = (int)gaeA;
          int GaeB = (int)gaeB;
          int temp = GaeA-GaeB;
          rtChngY = temp/10000;
          System.out.println(&quot;rtChngY = &quot;+rtChngY);   
      }
      
              
  }
  </code></pre>