Three methods of Java separator __string go to separator

Source: Internet
Author: User

The string is processed using the

Method One:

String str = "1,000";
str = str. Replace (",", "");

Method Two:

String str = "100,000,000";

String str1 = "";
string[] A = str. Split (', ');
for (int i = 0; I <= a.length-1; i++) {
STR1 + = A[i];
}

Method Three:

Using DecimalFormat

Implement formatting in the format you want please look down--------------------------decimalformat usage
DecimalFormat is a specific subclass of NumberFormat that is used to format decimal digits.

DecimalFormat contains a pattern and a set of symbols


Symbolic Meaning:  

01 digits  

# A number, excluding 0 ,

. Placeholder   for separator of decimal,

, placeholder for grouping delimiters  

, separating the formatting. &NBSP

-default negative number prefix. &NBSP

% multiplied by 100 and displayed as a percentage  

multiplied by 1000 and displayed as a thousand currency symbol, replaced by currency notation, and replaced with a  

International currency symbol if double write. If it appears in a pattern, the   is replaced with the currency decimal separator, and the

is the decimal separator. Any other character used in the  

X prefix or suffix to refer to the special characters in the prefix or suffix. &NBSP

Example:  

DecimalFormat df1 = new DecimalFormat ("0.0");  

DecimalFormat df2 = new Deci Malformat ("#.#");  

DecimalFormat df3 = new DecimalFormat ("000.000");  

DecimalFormat df4 = new DecimalFormat ("###.###");  

System.out.println (Df1.format (12.34));  

System.out.println ( Df2.format (12.34));  

System.out.println (Df3.format (12.34));  

System.out.println ( Df4.format (12.34));  

Result:  

12.3 

12.3 

012.340 

12.34

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.