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