2021年2月9日星期二

I can't truncate a number to be compared

I need to compare numbers of decimal type, where the comparison will be made up to decimal number three but with the code that I have it cannot do it.

I have tried round as well but it is not achieved either The code is the following:

the number compare=

-3.1756 ; -3.175 this is true

3.174 ; 3.175 this is false

public static boolean areEqualByThreeDecimalPlaces(double one, double two)
int a = (int) Math.floor(one*1000);  int b = (int) Math.floor((two*1000));        if(a == b){          System.out.println(true);          System.out.println(a + "---" + b);          return true;      }      else            System.out.println(false);      System.out.println(a + "---" + b);      return false;  
https://stackoverflow.com/questions/66130224/i-cant-truncate-a-number-to-be-compared February 10, 2021 at 10:46AM

没有评论:

发表评论