A double is similar to the int except that a double allows for decimal places.

As an example, if you wanted to display the number 10.666666666 or 10.4 you could use a double. If you wanted to display a number like 5000 or 4 you could use an int.

Here is an example of how to use a double:

double pitch = 10.666666666;

The word ‘double’ is a type which tells the computer what type of variable you want to use. Following this by the word ‘pitch’ (you can pick your own word here), I am assigning the double to a variable called ‘pitch’

Another way to think of it is that I have a double (type) and I am placing inside of a box(Variable) named ‘pitch’

By doing ‘=’ followed by a decimal number such as 10.666666, you are assigning the double called ‘pitch’ a value.

To print this on the console you need to use the Console.WriteLine() function which looks like this: –

Console.WriteLine(pitch);

This is tells the computer to print a line on the console that contains the content of the variable assigned the name ‘pitch’

Put the two lines together…

double pitch = 10.666666666;
Console.WriteLine(pitch);

…and this is the result that gets printed on the console:

10.666666666

If you need further clarrification on the Console.WriteLine() function see This Post.

Comment any questions below!


Discover more from

Subscribe to get the latest posts sent to your email.

Leave a comment

Trending