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