Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to convert a specified value to a 64-bit signed integer (Convert.ToInt64) in C#

1 Answer

0 votes
using System;

public class Program
{
    public static void Main(string[] args)
    {
        float[] arr = { Single.MinValue, -2.18e10f, -4012.309f, -18.07f,
                        0f, 7.018e-16f, 981.276f, 23004.7815f, Single.MaxValue };
        
        foreach (float value in arr) {
            try {
                long result = Convert.ToInt64(value);
                Console.WriteLine("{0} = {1}", value, result);
            }
            catch (OverflowException) {
                Console.WriteLine("{0} is outside the range of the Int64 type", value);
            }
        }
    }
}



/*
run:

-3.402823E+38 is outside the range of the Int64 type
-2.18E+10 = -21799999488
-4012.309 = -4012
-18.07 = -18
0 = 0
7.018E-16 = 0
981.276 = 981
23004.78 = 23005
3.402823E+38 is outside the range of the Int64 type

*/

 



answered May 24, 2024 by avibootz
...