C # What is the difference between converting floating point type to integer using Int. tryparse, convert. toint32, (INT )?

Source: Internet
Author: User

Int. tryparse, convert. toint32, (INT)

These types differ in convert when converting the floating point type to an integer. toint32 is rounded to int. tryparse can only be converted to integers, that is, if the floating point type is all, 0 (INT) is returned and no rounding is performed. Only the integer part is taken. The decimal part is completely discarded.
UsingSystem;
Public ClassDoubletoint
{
Public Static VoidMain ()
{
Test_doubletoint (0.4 );
Test_doubletoint (0.5 );
Console. readkey ();
}
Static VoidTest_doubletoint ( Double_ Testnumber)
{
Int_ I = 0;
For( IntI = 0; I <10; I ++)
{
If(I! = 0 ){
_ Testnumber + = 1;
}
Console. writeline ( String. Format ("(INT) {0} = {1}", _ testnumber ,( Int) (_ Testnumber )));

Console. writeline ( String. Format ("convent. toint32 ({0}) = {1}", _ testnumber, convert. toint32 (_ testnumber )));
// Int. tryparse only converts the integer type. Otherwise, 0 is returned.
Int. Tryparse (_ testnumber. tostring (), Out_ I );
Console. writeline ( String. Format ("int. tryparse ({0}) = {1}", _ testnumber, _ I ));
}
Console. writeline ( String. Empty );
}}

 

 

Http://www.cnblogs.com/Dely/p/3791951.html

Http://stackoverflow.com/questions/11431793/convert-toint32-rounds-to-the-nearest-even-number

Http://stackoverflow.com/questions/311696/why-does-net-use-bankers-rounding-as-defaul

Related Article

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.