How to convert double to long in C#

2 Answers

0 votes
using System;

class Program
{
    static void Main() {
        double d = 73476.871;

        long l = Convert.ToInt64(d);

        Console.Write(l);
    }
}




/*
run:

73477

*/

 



answered Feb 9, 2021 by avibootz
edited May 11, 2024 by avibootz
0 votes
using System;
 
public static class Program
{
    public static void Main()
    {
        double dbl = 10510.49;
 
        long l = Convert.ToInt64(dbl);
 
        Console.WriteLine(l);
 
        dbl = 10510.50;
        Console.WriteLine(Convert.ToInt64(dbl));
 
        dbl = 10510.51;
        Console.WriteLine(Convert.ToInt64(dbl));
    }
}
 
 
 
 
 
/*
run:
 
10510
10510
10511
 
*/

 



answered May 11, 2024 by avibootz

Related questions

1 answer 161 views
161 views asked Feb 12, 2021 by avibootz
1 answer 76 views
1 answer 151 views
151 views asked Nov 15, 2021 by avibootz
2 answers 209 views
209 views asked Nov 7, 2021 by avibootz
1 answer 196 views
1 answer 304 views
304 views asked Jun 20, 2021 by avibootz
...