我有一个字符串对象

String s = "64.5369474 British pounds"

我想要的是一种可以将数字取出并转移到小数点后两位的方法,
我期望得到的结果是这样的:
String result = "64.54 British pounds"

有什么建议么?

最佳答案

DecimalFormat df = new DecimalFormat("00.00");
String unformatedMoney = "65.432784327489";
String formattedMoney = df.formart(unformattedMoney);
System.out.println(formattedMoney + " British pounds");

关于java - 从字符串中提取数字并转换为小数点后2位,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18558461/

10-11 22:22
查看更多