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 ...
Hello 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.
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:
Now, let's add the code behind this form, so your code will look something as shown in below figure:
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:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Variables
{
public partial class Form1 : Form
{
double a = 2.5;
double b = 2.6;
double c;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ClickHere_Click(object sender, EventArgs e)
{
c = a + b;
txtClick.Text = c.ToString();
}
}
}
So, now run your project and then click the button and you will get results as shown in below figure:
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. :)
syedzainnasir
I am Syed Zain Nasir, the founder of The Engineering Projects (TEP). I am a
programmer since 2009 before that I just search things, make small projects and now I am sharing my
knowledge through this platform. I also work as a freelancer and did many projects related to
programming and electrical circuitry. My Google Profile+Follow
Get Connected
Comments on ‘’ How to use C# Double Variables ‘’ ( 0 )