如何从float结果中删除小数?

Geo*_*ngu 1 floating-point android integer

在我的应用程序中,我计算CPU使用率,我得到的结果为%但有时结果太大20.234234234234我的问题是,如何在"."之后完全删除结果数字?
我可以这样做而不将float改为整数吗?

这是我的代码:

    private float readCpuUsage() {
    try {
        RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
        String load = reader.readLine();

        String[] toks = load.split(" ");

        long idle1 = Long.parseLong(toks[5]);
        long cpu1 = Long.parseLong(toks[2]) + Long.parseLong(toks[3])
                + Long.parseLong(toks[4]) + Long.parseLong(toks[6])
                + Long.parseLong(toks[7]) + Long.parseLong(toks[8]);

        try {
            Thread.sleep(360);
        } catch (Exception e) {
        }

        reader.seek(0);
        load = reader.readLine();
        reader.close();

        toks = load.split(" ");

        long idle2 = Long.parseLong(toks[5]);
        long cpu2 = Long.parseLong(toks[2]) + Long.parseLong(toks[3])
                + Long.parseLong(toks[4]) + Long.parseLong(toks[6])
                + Long.parseLong(toks[7]) + Long.parseLong(toks[8]);

        return (float) (cpu2 - cpu1) / ((cpu2 + idle2) - (cpu1 + idle1));

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

要打印结果我只是抛出:

      textview.setText((readCpuUsage() * 100) + "%");
Run Code Online (Sandbox Code Playgroud)

其中readCpuUsage()是结果并将其转换为%i将其乘以100
这就是我这样做的方式:

    float xxz=readCpuUsage()*100;
    textview.setText(String.format("%.0f",xxz) + "%");
Run Code Online (Sandbox Code Playgroud)

Abh*_*tel 12

试试这可能对你有所帮助

String.format("%.0f",floatvalue);
Run Code Online (Sandbox Code Playgroud)

要么

Float.parseFloat(String.format("%.0f",floatvalue))
Run Code Online (Sandbox Code Playgroud)