如何从 string.format() 使用 .而不是,?
How to get result from string.format() with . and not with ,?
它 returns 我 1014,66 但我希望它返回 1014.66 。有什么建议吗?
double money = 1000;
double last = money * 1 * 1.04166;
String gift = String.format("%1$,.2f",last);
使用带有 Locale
的 String.format
方法版本,并指定一个区域设置,该区域设置使用点作为小数点分隔符而不是逗号。例如,美国语言环境:
String gift = String.format(Locale.US, "%1$,.2f", last);
您可以使用此代码
double money=1014.66;
String str_money=String.valueOf(money);
str.replace(',','.');
return str;
它 returns 我 1014,66 但我希望它返回 1014.66 。有什么建议吗?
double money = 1000;
double last = money * 1 * 1.04166;
String gift = String.format("%1$,.2f",last);
使用带有 Locale
的 String.format
方法版本,并指定一个区域设置,该区域设置使用点作为小数点分隔符而不是逗号。例如,美国语言环境:
String gift = String.format(Locale.US, "%1$,.2f", last);
您可以使用此代码
double money=1014.66;
String str_money=String.valueOf(money);
str.replace(',','.');
return str;