如何在java中格式化此字符串?
如何在Java中格式化字符串 我的字符串只包含像“1234.0”这样的数字,我想返回格式化的数字如何在java中格式化此字符串?,java,string,Java,String,如何在Java中格式化字符串 我的字符串只包含像“1234.0”这样的数字,我想返回格式化的数字 例如,给定字符串“1234.0”,结果应为字符串“1234”。使用以下格式: DecimalFormat myFormatter = new DecimalFormat("####"); String output = myFormatter.format(value); 您可以找到更多您还可以使用正则表达式: String n = "1234.0"; n.replaceAll("\\.0*$",
例如,给定字符串“1234.0”,结果应为字符串“1234”。使用以下格式:
DecimalFormat myFormatter = new DecimalFormat("####");
String output = myFormatter.format(value);
您可以找到更多您还可以使用正则表达式:
String n = "1234.0";
n.replaceAll("\\.0*$", "");
您只想删除小数点位置吗?不需要四舍五入吗?你尝试过什么?
String formatted=String.format(format,args…
确实会帮助你成为“懒惰的程序员”。程序员常用的一种方法是。。。编写代码。或者删除逗号后的每个字符(从字符串开头到逗号的子字符串)。
try {
String formatted = String.valueOf((int)Double.parseDouble("12345.0"));
} catch (ParseException e) {
// input is not a number
}