From the course: Rust Essential Training
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Formatting print statements - Rust Tutorial
From the course: Rust Essential Training
Formatting print statements
- [Instructor] The print line macro is incredibly useful to display a string of information. And Rust has lots of formatting options to control how that information gets presented. So, let's look at some of those. The print line macro here on line five is currently using the default formatting. And when I run this program, we see that the floating point result of 10 divided by 3 is displayed as 3.333 repeating. Until the floating point reaches the limit of its precision. We can control the number of decimal places to show by including additional formatting information between the curly braces that get replaced by the value of c. This sequence of :.3 tells the print line macro to display the value with exactly three decimal places of precision. And when I run this program, we can see that's the result. But the string formatting options don't just end there. We can tell the formatter how many total character spaces we want…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Declaring variables5m 46s
-
(Locked)
Integer data types6m 51s
-
(Locked)
Floating-point data types5m 34s
-
(Locked)
Arithmetic operations6m 37s
-
(Locked)
Formatting print statements5m 40s
-
Bitwise operations10m 46s
-
(Locked)
Boolean data type and operations5m 4s
-
(Locked)
Comparison operations3m 5s
-
Char data types2m 36s
-
(Locked)
Challenge: Find the average1m 20s
-
(Locked)
Solution: Find the average3m 20s
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-