Java 如何将印度货币兑换成双倍?
我想把印度货币兑换成双倍。下面是我的代码:Java 如何将印度货币兑换成双倍?,java,number-formatting,currency-formatting,Java,Number Formatting,Currency Formatting,我想把印度货币兑换成双倍。下面是我的代码: String initalAmount = "2341"; Format format = NumberFormat.getCurrencyInstance(new Locale("en", "in")); String convertedAmountToINR = format.format(new BigDecimal(initalAmount)); // it prints Rs. 2,341.00 现在,我想把它转换成DOUBLE-like2
String initalAmount = "2341";
Format format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
String convertedAmountToINR = format.format(new BigDecimal(initalAmount));
// it prints Rs. 2,341.00
现在,我想把它转换成DOUBLE-like2341.00。我尝试了几种方法让它工作,但没有成功。请像这样尝试
double doubleINR=Double.parseDouble(convertedAmountToINR);
对于您的情况,请尝试以下内容:
double d=Double.parseDouble(convertedAmountToINR.replaceAll("Rs.|,", ""));
请像这样试试
double doubleINR=Double.parseDouble(convertedAmountToINR);
对于您的情况,请尝试以下内容:
double d=Double.parseDouble(convertedAmountToINR.replaceAll("Rs.|,", ""));
您应该将initialAmount转换为双精度,如下所示:
Double.valueOf(initalAmount);
无法将
convertedAmountToINR
转换的原因是其中的“Rs.”无法转换为双精度。您应该将initialAmount转换为双精度,如下所示:
Double.valueOf(initalAmount);
无法将
convertedAmountToINR
转换的原因是其中的“Rs.”无法转换为双精度。如果确实需要,可以使用相同的格式
对象将convertedAmountToINR
转换回:
NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
double value = format.parse(convertedAmountToINR).doubleValue();
这将只分析使用此format对象格式化的字符串。如果确实需要,可以使用相同的
format
对象将convertedAmountToINR
转换回:
NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
double value = format.parse(convertedAmountToINR).doubleValue();
这将只分析使用此format对象格式化的字符串。为什么不存储新的BigDecimal值并使用它?这看起来像是我的家庭作业。你可以用
double d=double.parseDouble(initalAmount)将它转换成一个double但是我不认为这就是你的意思。为什么不存储新的BigDecimal值并使用它呢?这看起来像是我的家庭作业。你可以用double d=double.parseDouble(initalAmount)将它转换成一个double但我不认为你是这个意思……回答得很好。这对我有用。如果你能提供一些关于使用过的正则表达式的描述,那就更好了。这对我有用。如果您为使用过的正则表达式提供一点说明,效果会更好。