有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

单元测试中的java DecimalFormat(“·#,##0”)前缀

我正在为格式化一些数字的方法编写单元测试,当我在单元测试中使用DecimalFormat("¤#,##0")时,它总是以Â作为前缀。它不会在写入数字的XML输出文件中显示Â,但会在单元测试中显示。例如:

DecimalFormat decimalFormat = new DecimalFormat("¤#,##0");
String str = decimalFormat.format(5000);

XML输出文件将保存值$5,000,但在调试或单元测试时str = "Â$5,000"

这是预期的行为还是出了什么问题?文件(http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html)说

Currency sign, replaced by currency symbol. If doubled, replaced by international currency symbol. If present in a pattern, the monetary decimal separator is used instead of the decimal separator.

我知道它可能是从默认语言环境中获取货币符号,但是为什么会出现Â

如果期望的行为很好,我将使用replace方法,但是如果不期望的话,我想知道发生了什么


共 (0) 个答案