int, float, double in. NET of mutual transformation

Source: Internet
Author: User
Tags number sign

When we recently checked a server in our company, we found that many Systemtonumber crash Exception were recorded in the Windows log because of the fact that the company's colleague coding had made a most basic principle error, in view of this, I think it's necessary to comb it again. NET three basic numeric types (int, float, double).

int : in. NET ,int is a signed 32-bit integer value whose . NET Framework type is System.Int32 , regardless of whether the processor is a four-bit or a.

Float: Single-precision floating-point number, 32-bit length, 1-bit real number sign bit (original code), 1-bit exponential sign bit, 7-bit exponential bit (this eight bit is a shift code representation), and 23-bit data bits (complement), in. NET is also known as single.

double:64 bit-length double-precision floating-point number, 1-bit sign bit, 11-bit exponential bit, 52-bit data bit.

The conversion relationship of the three:

1. int can be implicitly converted to float and double;

2.float can be cast to an int only, but may be implicitly converted to double;

3.double can only be cast to float and int.

Ps:

Note the distinction: (1) Convert.ToInt32 ("56.89") and (2) convert.toint (56.89)

(1) This writing will cause the formatexception to be thrown, so use (2) this notation.

int, float, double in. NET of mutual transformation

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.