我本來可以使用Decimal Format
,但在這種情況下我必須使用regex
。 我有以下字符串myString =「0.44587628865979384」;我需要把它修剪到小數點後三位,使得看起來0.445如何使用`正則表達式'修剪已解析的字符串?
我試過如下:
String myString = "0.44587628865979384";
String newString = myString.replaceFirst("(^0$.)(\\d{3})(\\d+)","$1$2");
// But this does not work. What is the problem in here?
也許'.' - >'\\。'? – 2013-04-24 19:05:31