pcbway





c# double, double c#, c# double variable, C# double to intHello friends, hope you all are fine and having fun with your lives. Today, I am going to show you guys How to use C# Double Variable in your projects. In our previous tutorial, we have seen How to use C# Int Variable and we have also discussed about the term Variables in detail. So, I am not gonna discuss it again and gonna come straight to our topic C# Double variable.

It’s my second C# tutorial in the series of C# variables. In the coming tutorials, I will discuss the remaining C# variables in detail. I have also provided the project code below but I would suggest you to do it on your own so that you get most out of it.  Moreover, you should also have a look at Introduction to C# Windows Forms and How to use C# Control in Widows Forms as I am gonna use two C# Controls in today’s tutorial as I did in C# Int tutorial. So, let’s get started with How to use C# Double Variable:

How to use C# Double Variable ???

  • C# double variable can store 64 bit value in it.
  • C# double can store integer as well as decimal values means you can save decimal values like 5.2, 3.1 as well as simple integers like 2, 5, 38 etc.
  • C# double variable approximate value is ±5.0 × 10^−324 to ±1.7 × 10^308 as per Microsoft Official Page and its precision is 15-16 digits.
  • So, first of all, design a new simple C# project as we did in Introduction to C# Windows Forms.
  • I am not gonna design a new one, instead I am gonna use the same project as I did for C# Int Variable.
  • So after creating a new project, add a Button and a Text Box in it as we did in How to add C# Controls in Windows form.
  • Now, I hope that you are done with the front end of your C# Project and it will look something as shown in below figure:

c# double, double c#, c# double variable, C# double to int

  • Now, let’s add the code behind this form, so your code will look something as shown in below figure:

c# double, double c#, c# double variable, C# double to int

  • Now if you have a look at it then you will see that its exactly the same code as we did for C# Int variables.
  • But there’s a slight difference that now all of the three variables a, b and c are double instead of int.
  • That’s why I have assigned decimal values to them where a = 2.5 while b = 2.6.
  • C# Int variable can’t use these value because these are not integers but double can easily handle them.
  • So, now their result should be 5.1 which is again a double so that’s why our third variable is also double.
  • Here’s the code for you to copy:

  • So, now run your project and then click the button and you will get results as shown in below figure:

c# double, double c#, c# double variable, C# double to int

  • So, now you can see the value saved in C# double variable c was 5.1 which is now displayed in the Text Box.

So, that’s all for today. I hope you guys have now understood How to use C# double variables in your projects. Thanks for reading. Have fun and take care. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment