Convert between BigDecimal and long int

Source: Internet
Author: User

Interchange between BigDecimal and long, int

In the actual development process, BigDecimal is a frequently used data type that can be converted to and from int long.

The conversion relationship is shown in the following code:

int converted to BigDecimal data type

int converted to BigDecimal type

public static void Inttobigdecimal () {

int b = 5;

BigDecimal a = new BigDecimal (b);

The data type of System.out.println (A + "is" +a.getclass (). GetName ());

}

Lont Convert to BigDecimal data type

The Long type is converted into BigDecimal

public static void Longtobigdecimal () {

Long B = 5;

BigDecimal a = new BigDecimal (b);

The data type of System.out.println (A + "is" +a.getclass (). GetName ());

}

BigDecimal Convert to Long data type

BigDecimal Convert to Long type

public static void Bigdecimaltolong () {

BigDecimal B = new BigDecimal (12);

Long C = B.longvalue ();

The data type of SYSTEM.OUT.PRINTLN (c+ "is" +c.getclass (). GetName ());

}

BigDecimal Convert to int data type

BigDecimal Convert to int type

public static void Bigdecimaltoint () {

BigDecimal B = new BigDecimal (12);

int c = B.intvalue ();

}

Category: Java Basics

Tags: long, int, BigDecimal, BigDecimal and int conversions, BigDecimal and long conversions

Convert between BigDecimal and long int

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.