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 170 views
170 views asked Feb 12, 2021 by avibootz
1 answer 81 views
1 answer 161 views
161 views asked Nov 15, 2021 by avibootz
2 answers 218 views
218 views asked Nov 7, 2021 by avibootz
1 answer 206 views
1 answer 313 views
313 views asked Jun 20, 2021 by avibootz
...