方法一,使用substring方法:

import java.math.BigDecimal;
 
public class Test1 {
 
    public static void main(String[] args) {
        String a = "18.89%";
        String b = "18.88%";
        //去掉%
        String tempA = a.substring(0, 5);
        String tempB = b.substring(0, 5);
        //精确表示
        BigDecimal dataA = new BigDecimal(tempA);
        BigDecimal dataB = new BigDecimal(tempB);
        System.out.println(dataA.compareTo(dataB));//大于为1,相同为0,小于为-1
 
    }
}

 

方法二,使用replace方法:

public class Test2 {
    
    public static void main(String[] args) {

        String data1 ="80%";
        String data2 ="90%";
        String coverdata1 =data1.replace("%","");
        String checkdata2 =data2.replace("%","");
        int coverdate = Integer.parseInt(coverdata1);
        int checkdata = Integer.parseInt(checkdata2);
        if(coverdate<checkdata) {
        System.out.println(coverdate);
        System.out.println(checkdata);
         }

    
    }
  }