0
0
C Sharp (C#)programming~5 mins

Floating point types (float, double, decimal) in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the difference between float, double, and decimal in C#?

float is a 32-bit floating point type, double is 64-bit, and decimal is 128-bit with higher precision for financial calculations.

float and double are binary floating point types, while decimal is a decimal floating point type, reducing rounding errors in money calculations.

Click to reveal answer
beginner
How do you declare a float variable with the value 3.14 in C#?

You write: float pi = 3.14f;

The f suffix tells the compiler this is a float literal, not a double.

Click to reveal answer
intermediate
Why is decimal preferred for financial calculations over float or double?

decimal has higher precision and uses base-10 representation, which reduces rounding errors common in binary floating point types like float and double.

This makes decimal better for money where exact decimal values matter.

Click to reveal answer
beginner
What is the default floating point type for literals like 3.14 in C#?

The default type is double.

If you want a float, you must add f or F suffix, and for decimal, use m or M.

Click to reveal answer
intermediate
What happens if you assign a double value to a float variable without casting?

The compiler will give an error because double has more precision and size than float.

You must explicitly cast it like float f = (float)myDouble; to avoid errors.

Click to reveal answer
Which floating point type in C# has the highest precision?
Adecimal
Bdouble
Cfloat
Dint
What suffix do you use to declare a float literal in C#?
Af
Bd
Cm
Dl
What is the default type of the literal 5.0 in C#?
Afloat
Bdouble
Cdecimal
Dint
Which type is best for money calculations to avoid rounding errors?
Afloat
Bdouble
Cdecimal
Dlong
What must you do to assign a double value to a float variable?
ANothing, it works automatically
BUse suffix 'd' on the float variable
CUse suffix 'f' on the double value
DUse explicit cast like (float)
Explain the differences between float, double, and decimal types in C# and when to use each.
Think about precision and typical scenarios like graphics, science, and money.
You got /4 concepts.
    Describe how to correctly declare and assign floating point literals in C# for each type.
    Remember the suffixes and what happens if you omit them.
    You got /3 concepts.