How to cast big numbers to int in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            double d = 10000000000;

            Console.WriteLine((int)d);

            d = -10000000000;
            Console.WriteLine((int)d);

            d = 100000000000000;
            Console.WriteLine((int)d);

            d = 1000000000;
            Console.WriteLine((int)d);
        }
    }
}


/*
run:
  
-2147483648
-2147483648
-2147483648
1000000000
 
*/

 



answered Jan 12, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            long l = 10000000000;

            Console.WriteLine((int)l);

            l = -10000000000;
            Console.WriteLine((int)l);

            l = 100000000000000;
            Console.WriteLine((int)l);

            l = 1000000000;
            Console.WriteLine((int)l);
        }
    }
}


/*
run:
  
1410065408
-1410065408
276447232
1000000000
 
*/

 



answered Jan 12, 2017 by avibootz

Related questions

1 answer 130 views
130 views asked May 19, 2021 by avibootz
2 answers 190 views
1 answer 106 views
106 views asked Jan 10, 2024 by avibootz
2 answers 137 views
137 views asked Nov 25, 2020 by avibootz
1 answer 175 views
1 answer 83 views
...