Convert double to Int, rounded down

前端 未结 5 1944
猫巷女王i
猫巷女王i 2020-12-15 02:27

How to convert a double value to int doing the following:

Double If x = 4.97542. Convert to int x = 4.

Double If x = 4.23544. Conv         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 03:17

    I think I had a better output, especially for a double datatype sorting.

    Though this question has been marked answered, perhaps this will help someone else;

    Arrays.sort(newTag, new Comparator() {
             @Override
             public int compare(final String[] entry1, final String[] entry2) {
                  final Integer time1 = (int)Integer.valueOf((int) Double.parseDouble(entry1[2]));
                  final Integer time2 = (int)Integer.valueOf((int) Double.parseDouble(entry2[2]));
                  return time1.compareTo(time2);
             }
        });
    

提交回复
热议问题