How to use C# Double Variables

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:
- 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.
×
![]()





































































