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

Floating point types (float, double, decimal) in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Floating Point Types in C#
📖 Scenario: You are creating a simple program to store prices of items in a store. Different types of floating point numbers are used to understand how they behave with money values.
🎯 Goal: Build a C# program that declares variables using float, double, and decimal types, assigns values, calculates a total price, and prints the result.
📋 What You'll Learn
Create three variables named priceFloat, priceDouble, and priceDecimal with types float, double, and decimal respectively.
Assign the value 19.99 to each variable using the correct suffix for float and decimal types.
Create a variable called quantity of type int and assign it the value 3.
Calculate the total price for each type by multiplying the price by the quantity.
Print the total prices with clear labels.
💡 Why This Matters
🌍 Real World
Floating point types are used in programs that handle measurements, prices, and scientific calculations where decimals are needed.
💼 Career
Understanding float, double, and decimal types is important for software developers working with financial applications, games, simulations, and data analysis.
Progress0 / 4 steps
1
Declare floating point variables
Create three variables: priceFloat of type float with value 19.99f, priceDouble of type double with value 19.99, and priceDecimal of type decimal with value 19.99m.
C Sharp (C#)
Need a hint?

Remember to add f after the number for float and m for decimal values.

2
Declare quantity variable
Create an integer variable called quantity and assign it the value 3.
C Sharp (C#)
Need a hint?

Use int type for whole numbers like quantity.

3
Calculate total prices
Create three variables: totalFloat, totalDouble, and totalDecimal. Calculate each by multiplying the corresponding price variable by quantity.
C Sharp (C#)
Need a hint?

Multiply price by quantity for each type and store in a new variable.

4
Print total prices
Print the values of totalFloat, totalDouble, and totalDecimal with labels: "Total price (float):", "Total price (double):", and "Total price (decimal):" respectively.
C Sharp (C#)
Need a hint?

Use Console.WriteLine to print each total with the correct label.