How to get the first digit of float number in Java

1 Answer

0 votes
public class MyClass {

    public static void main(String args[]) {
        float f = 98.5271f;
     
        System.out.println((int)Float.parseFloat(Float.toString(f).substring(0, 1)));

    }
}



/*
run:

9

*/

 



answered Aug 27, 2019 by avibootz

Related questions

...