java 字符串格式化 人民币格式,带有货币符号的Java String.format

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

String.format( pattern, value )

Note that I cannot change the code itself - I can only change the format pattern supplied to the code.

What is the format pattern to output a currency symbol for the default locale? Essentially, I want to achieve the following output:

String.format( "...", 123 ) => $ 123

解决方案

With the constraints you have given, I think it is impossible to achieve it.

To get to the current Locale's currency symbol, you'll need a minimum of code.

If you have absolutely no means to add code to the program, you'd best use the established symbol for "currency" (¤). It was established for this exact purpose, to symbolize currency absent any more specific symbol.

If you can't change the given code, but add code to the project as a whole, you can use that to find out the symbol best used. Once you have it, you can use it to create a pattern for the existing code to use for formatting.

If you can find out in which Locale the original program will run in next, you could write a assistant program that uses that setting to fill your configuration.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值