2014-11-03 70 views
-1

我想組織一個這樣的數字「999.99.999」我如何組織一個號碼?

這個數字的長度總是8個字符。

12314156 => 123.14.156

我如何格式化?

+0

描述你嘗試過什麼?如果您希望我們爲您做到這一點,那麼您來錯了地方。我建議你檢查正則表達式(或子字符串)和字符串格式。 – m0skit0 2014-11-03 11:16:48

回答

0

您可以在java中使用format,就像在C中使用printf一樣,甚至可以使用System.out.printf

0

您可以參數化下面的代碼。

Matcher m = Pattern.compile("(\\d{3})(\\d{2})(\\d{3})").matcher("99999999"); 
if(m.matches()){    System.out.println(m.group(1).concat(".").concat(m.group(2)).concat(".").concat(m.group(3))); 
}