Зміст курсу
C# Basics
C# Basics
Floating-Point and Double
Floating point numbers, also called floats, represent decimal numbers. We can declare a variable of type float using the float
keyword:
main
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
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 | |
float | 6-9 digits |
double | 15-17 digits |
Like int
and long
, we can also perform arithmetic operations on float
and double
values.
main
Все було зрозуміло?