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

Floating point types (float, double, decimal) in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Floating Point Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of floating point addition with float and double
What is the output of this C# code snippet?
C Sharp (C#)
float a = 0.1f;
double b = 0.1;
Console.WriteLine(a == b);
ATrue
BRuntime exception
CFalse
DCompilation error
Attempts:
2 left
💡 Hint
Consider how float and double represent decimal numbers differently.
Predict Output
intermediate
2:00remaining
Decimal precision in financial calculation
What is the output of this C# code?
C Sharp (C#)
decimal price = 19.99m;
decimal quantity = 3m;
decimal total = price * quantity;
Console.WriteLine(total);
A59.969999999999999
B59.97
C60
DCompilation error
Attempts:
2 left
💡 Hint
Decimal type is designed for exact decimal representation.
Predict Output
advanced
2:00remaining
Result of mixed type arithmetic with float, double, and decimal
What is the output of this C# code?
C Sharp (C#)
float f = 1.5f;
double d = 2.5;
decimal m = 3.5m;
var result = f + (float)d;
Console.WriteLine(result);
A4
B3.9999998
C4.0
DCompilation error
Attempts:
2 left
💡 Hint
Consider whether these values are exactly representable in float precision.
Predict Output
advanced
2:00remaining
Effect of floating point precision on equality check
What does this C# code print?
C Sharp (C#)
double x = 0.1 + 0.2;
bool equal = x == 0.3;
Console.WriteLine(equal);
ARuntime exception
BTrue
CCompilation error
DFalse
Attempts:
2 left
💡 Hint
Floating point addition can introduce small errors.
🧠 Conceptual
expert
2:00remaining
Choosing the correct floating point type for currency calculations
Which floating point type should you use in C# for precise currency calculations to avoid rounding errors?
Adecimal
Bdouble
Cfloat
Dint
Attempts:
2 left
💡 Hint
Think about which type stores decimal numbers exactly without binary rounding errors.