1.23 determine the integer part of a decimal or double

Source: Internet
Author: User
Knowledge point:

1. system. Math. Pi

2. system. Math. truncate () // get the integer

Problem:

You need to find the integer part of a decimal or double number.

Solution

If a decimal or double number is truncated to the number closest to 0, the integer is obtained. Therefore, you can use the overloaded static system. Math. truncate method. This method takes a decimal or double as the parameter and returns the same type.

1 using system; 2 using system. collections. generic; 3 using system. LINQ; 4 using system. text; 5 using system. threading. tasks; 6 7 namespace _ 07 determine the integer part of a decimal or double 8 {9 class program10 {11 static void main (string [] ARGs) 12 {13 decimal Pi = (decimal) system. math. pi; 14 decimal Decret = system. math. truncate (PI); 15 console. writeline (Decret); 16 console. readkey (); 17 18 double trouble = 5.555; 19 double decret2 = system. math. truncate (trouble); 20 console. writeline (decret2); 21 console. readkey (); 22} 23} 24}
View code

 


Verification Result

1. Decret = 3

2. decret2 = 5

1.23 determine the integer part of a decimal or double

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.