gpt4 book ai didi

java - NumberFormat API 说明

转载 作者:行者123 更新时间:2023-12-01 04:23:24 25 4
gpt4 key购买 nike

直接从此 API:

NumberFormat helps you to format and parse numbers for any locale. Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.

它们的含义是什么,甚至使用的特定十进制数字是什么意思,或者数字格式是否是偶数十进制。

最佳答案

我可以举一个这样的例子——日元。在日元中,没有什么比 1.2 日元更好的了;它始终是整数,最低面额是 1 日元。因此,日元货币金额永远不会有小数位。

在印度,100 万显示为 10,00,000;而美元则为 1,000,000。

运行以下代码来查看数字的区域设置的美妙之处:

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;


// The following example code demonstrates converting a number
// (double) into a formatted String according to different
// number formatting standards in various countries

public class FormatDecimalLocalFormat {

public static void main(String[] args) {

// circumference of earth in km
double number = 40075.168776;

// Germany
DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.GERMAN);
System.out.println(df.format(number));

// United states
df = (DecimalFormat) NumberFormat.getInstance(Locale.US);
System.out.println(df.format(number));

// China
df = (DecimalFormat) NumberFormat.getInstance(Locale.CHINESE);
System.out.println(df.format(number));

// France
df = (DecimalFormat) NumberFormat.getInstance(Locale.FRENCH);
System.out.println(df.format(number));

}
}

输出确认

Your code can be completely independent of the locale conventions for decimal points, thousands-separators, or even the particular decimal digits used, or whether the number format is even decimal.

40.075,169
40,075.169
40,075.169
40 075,169

关于java - NumberFormat API 说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18740190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com