2011-09-17 46 views

回答

2

這裏你如何做到這一點。

import java.text.DecimalFormat; 
    import java.text.DecimalFormatSymbols; 

    public class NewClass 
    { 
     public static void main(String[] args) 
     { 
      DecimalFormatSymbols phoneNumberSymbols = new DecimalFormatSymbols(); 

      // Use space not comma to thousands: 10 000 not 10,000. 
      phoneNumberSymbols.setGroupingSeparator('-'); 

      DecimalFormat phoneNumberFormat = new DecimalFormat("####,###,###", phoneNumberSymbols); 

      System.out.println("Some mobile number:" + phoneNumberFormat.format(567884968L)); 

     } 
    } 
1

如果你的手機號碼是一個字符串,這裏是解決方案:

import java.text.DecimalFormat; 
import java.text.DecimalFormatSymbols; 

public class NewClass { 

    public static void main(String[] args) { 

     long lg_tel = Long.parseLong(example.getString("tel")); // String to Long 
     DecimalFormatSymbols phoneNumberSymbols = new DecimalFormatSymbols(); 

     // Use space not comma to thousands: 10 000 not 10,000. 
     phoneNumberSymbols.setGroupingSeparator('-'); 

     DecimalFormat phoneNumberFormat = new DecimalFormat("####,###,###", phoneNumberSymbols); 

     (...) 
     tv.setText(phoneNumberFormat.format(lg_tel).toString()); 

    } 

}

相關問題