How to format money in Java

1 Answer

0 votes
import java.text.NumberFormat;

public class MyClass {
    public static void main(String args[]) {
        double d = 1247.95;
        
        NumberFormat formatter = NumberFormat.getCurrencyInstance();
        
        String s = formatter.format(d);
        
        System.out.println(s);
    }
}



/*
run:

$1,247.95

*/

 



answered Mar 25, 2021 by avibootz
...