Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Floating-Point and Double | Dealing with Data Types
C# Basics

Floating-Point and DoubleFloating-Point and Double

Floating point numbers, also called floats, represent decimal numbers. We can declare a variable of type float using the float keyword:

cs

main.cs

The letter 'f' in the value 3.14f tells the compiler that the value is of type float. Values of the float datatype should always be represented in this format.

The float data type has a limited precision so it can only store 6 to 9 digits after the decimal. There is another datatype called double which offers a higher precision:

cs

main.cs

As float has a lower precision, the value 3.1415926535897 is automatically rounded off till its 7th decimal digit and the result is stored in the variable myVar1.

precision
float6-9 digits
double15-17 digits

Like int and long, we can also perform arithmetic operations on float and double values.

cs

main.cs

question-icon

Which of these is the correct declaration of a float variable?

Виберіть кілька правильних відповідей

Все було зрозуміло?

Секція 2. Розділ 3
course content

Зміст курсу

C# Basics

Floating-Point and DoubleFloating-Point and Double

Floating point numbers, also called floats, represent decimal numbers. We can declare a variable of type float using the float keyword:

cs

main.cs

The letter 'f' in the value 3.14f tells the compiler that the value is of type float. Values of the float datatype should always be represented in this format.

The float data type has a limited precision so it can only store 6 to 9 digits after the decimal. There is another datatype called double which offers a higher precision:

cs

main.cs

As float has a lower precision, the value 3.1415926535897 is automatically rounded off till its 7th decimal digit and the result is stored in the variable myVar1.

precision
float6-9 digits
double15-17 digits

Like int and long, we can also perform arithmetic operations on float and double values.

cs

main.cs

question-icon

Which of these is the correct declaration of a float variable?

Виберіть кілька правильних відповідей

Все було зрозуміло?

Секція 2. Розділ 3
some-alt