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 322 views
2 answers 382 views
2 answers 378 views
2 answers 420 views
1 answer 316 views
1 answer 301 views
...