Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Числа з Плаваючою Комою та Double | Робота з Типами Даних
Quizzes & Challenges
Quizzes
Challenges
/
Основи C#

bookЧисла з Плаваючою Комою та Double

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

main.cs

main.cs

copy
1
float myVariable = 3.14f;

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:

main.cs

main.cs

copy
12345
float myVar1 = 3.1415926535897f; double myVar2 = 3.1415926535897; Console.WriteLine(myVar1); // Output: 3.1415927 Console.WriteLine(myVar2); // Output: 3.1415926535897

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.

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

main.cs

main.cs

copy
12345
float var1 = 1.14f; double var2 = 1.00; float var3 = 1.0f; double var4 = var1 + var2 + var3;
question mark

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

Select the correct answer

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you explain the main differences between float and double in C++?

When should I use float instead of double in my programs?

Can you show examples of arithmetic operations with float and double?

bookЧисла з Плаваючою Комою та Double

Свайпніть щоб показати меню

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

main.cs

main.cs

copy
1
float myVariable = 3.14f;

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:

main.cs

main.cs

copy
12345
float myVar1 = 3.1415926535897f; double myVar2 = 3.1415926535897; Console.WriteLine(myVar1); // Output: 3.1415927 Console.WriteLine(myVar2); // Output: 3.1415926535897

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.

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

main.cs

main.cs

copy
12345
float var1 = 1.14f; double var2 = 1.00; float var3 = 1.0f; double var4 = var1 + var2 + var3;
question mark

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

Select the correct answer

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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