将数字拆分为小数

Joo*_*lah -6 java string split

如何删除之后的所有字符/数字.在一个字符串中

String i = "154.232";

我只是想 154

谢谢

我的代码:

distance = crntLocation.distanceTo(newLocation)/1000; // in km
double newKB = Math.floor(distance);
String product_distance = String.valueOf(newKB);    
product_distance.replaceAll("\\..*", "");
Run Code Online (Sandbox Code Playgroud)

Ank*_*hal 5

 public static void main(String[] args) {
        String str = "154.232";
        str = str.replaceAll("\\..*", "");
        System.out.println(str);
    }
Run Code Online (Sandbox Code Playgroud)

要么

str.substring(0, str.indexOf("."));
Run Code Online (Sandbox Code Playgroud)

或//检查索引.是否-1,然后执行以下操作.

str.split(".")[0];
Run Code Online (Sandbox Code Playgroud)

产量

154
Run Code Online (Sandbox Code Playgroud)