0
0
Rustprogramming~15 mins

Floating point types in Rust - Mini Project: Build & Apply

Choose your learning style9 modes available
Floating point types
๐Ÿ“– Scenario: You are working on a simple calculator program that needs to handle decimal numbers accurately. You will learn how to use floating point types in Rust to store and work with decimal numbers.
๐ŸŽฏ Goal: Create floating point variables, perform a calculation, and display the result.
๐Ÿ“‹ What You'll Learn
Create floating point variables with exact values
Use a configuration variable for precision
Perform a calculation using floating point variables
Print the final result with specified precision
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Handling prices and taxes accurately is important in shopping apps, billing systems, and financial software.
๐Ÿ’ผ Career
Understanding floating point types and formatting is essential for software developers working with money, measurements, or scientific data.
Progress0 / 4 steps
1
Create floating point variables
Create two floating point variables called price and tax_rate with the exact values 19.99 and 0.07 respectively.
Rust
Need a hint?

Use let to create variables and specify the type f64 for floating point numbers.

2
Add a precision configuration variable
Create an integer variable called precision and set it to 2 to represent the number of decimal places to show.
Rust
Need a hint?

Use usize type for the precision variable.

3
Calculate total price with tax
Create a floating point variable called total_price that calculates the total by adding price and the tax amount (price * tax_rate).
Rust
Need a hint?

Use arithmetic operators to calculate the total price.

4
Print the total price with precision
Print the total_price rounded to precision decimal places using println! and format! macros.
Rust
Need a hint?

Use {:.2} in the format string to show two decimal places.