Float and decimal

Source: Internet
Author: User

RecentlyProgramThe float and decimal types are different in processing results.

You can write a program to calculate: float a = 2.2; float B = 6.6; float c = B/;

Decimal A = 2.2; decimal B = 6.6; decimal c = B/;

Guess the calculation result and execute the command to check the answer.

This is a very basic problem, but it is lacking in self-knowledge. Please refer to the following brief information:

X. XX. NET is doble by default.
If you want to specify the single-precision float type, you must add F/F
If you want to specify the decimal type, you must add m/m
If you want to specify double type, it is best to add D/d
Float (double) is theoretically insecure, which can reduce precision, while decimal is precise and safe.
 
It is very dangerous to use floating point numbers in exact calculations, although C # takes many measures in floating point operations to make the results of floating point operations look very normal.

However, if you do not know the characteristics of floating point numbers and use them rashly, it will cause serious risks.

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.