Challenge: Formatting Strings
Discover how to format and embed numerical values neatly in Scala strings. This lesson helps you practice controlling decimal precision to display quotients accurately up to three decimal places, improving your string manipulation skills.
We'll cover the following...
Problem Statement
You are given a variable quotient which stores the quotient of two numbers. You have to print the result of the quotient in such a way that the output only shows the quotient up to 3 decimal places.
Input
The input is the variable quotient.
quotienthas already been declared for you.
Output
The output will be the formatted quotient embedded in a string.
Sample Input
7 / 3
Sample Output
"The quotient is 2.333"
Test Yourself
Write your code in the given area. Try the exercise by yourself first, but if you get stuck, the solution has been provided. Good luck!
Let’s go over the solution review in the next lesson.