Java String.format with currency symbol

前端 未结 5 1866
广开言路
广开言路 2021-01-07 23:18

There is some existing code of the follow form which is used for format numerical values:

String.format( pattern, value )

5条回答
  •  无人及你
    2021-01-08 00:01

    You can try the following:

    public static void main(String[] args) {
        System.out.println(String.format(" %d \u20AC", 123)); // %d for integer
        System.out.println(String.format(" %.2f \u20AC", 123.10)); // %f for floats
    }
    

    This prints:

    123 €
    123.10 €
    

提交回复
热议问题