How to convert float to string with 2 decimal places in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        float f = 980284.8791f;
        
        String s = String.format("%.2f", f);
        
        System.out.println(s);
    }
}




/*
run:

980284.88

*/

 



answered Feb 12, 2023 by avibootz

Related questions

1 answer 204 views
2 answers 237 views
2 answers 205 views
2 answers 259 views
1 answer 209 views
1 answer 204 views
...