Conversion of Java primitive types

Source: Internet
Author: User

1. String into int

= "123"; Try {    int a =catch  (NumberFormatException e) {    e.printstacktrace ();}
= "123"; Try {    int b =catch  (NumberFormatException e) {    E.printstacktrace ();}

2. Double Turn int

Example 1: Double   D   =   12.0;    int   I   =   (new   Double (d)). Intvalue ();
Example 2: Double   D   =   12.0;    int   I   =   (int) D;   

3. Integer turns into string

New Integer (Ten= it.tostring ();

4, Integer to int

New Integer (Tenint k = i.intvalue (); i.e. Integer.intvalue ();

5, int turn to Integer

int converted to integer int i = tennew Integer (i);

6. String Turn BigDecimal

New BigDecimal (str);

7. Double type turn into string and format it by the way

double wcl=0.00; // Completion Rate String zzwcl=New Java.text.DecimalFormat ("0.00"). Format (WCL); // Final Completion rate  double replace string and format

Conversion of Java primitive types

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.