How to convert a decimal to a double in C#

2 Answers

0 votes
using System;

class Program
{
    static void Main() {
        decimal dec1 = 87236.908m;
        decimal dec2 = 0.43071m;
        decimal dec3 = -7612.8702m; 

        double d1 = Decimal.ToDouble(dec1);
        double d2 = Decimal.ToDouble(dec2);
        double d3 = Decimal.ToDouble(dec3);

        Console.WriteLine(d1);
        Console.WriteLine(d2);
        Console.WriteLine(d3);
    }
}




/*
run:

87236.908
0.43071
-7612.8702

*/

 



answered Jun 2, 2023 by avibootz
0 votes
using System;

class Program
{
    static void Main() {
        decimal x = 21672.747m;
        double d = (double) x / 20.0d;

        Console.Write(d);
    }
}




/*
run:

1083.63735

*/

 



answered Jun 2, 2023 by avibootz

Related questions

1 answer 149 views
149 views asked Nov 16, 2021 by avibootz
1 answer 137 views
1 answer 175 views
3 answers 345 views
3 answers 317 views
...