Rounding to a Specific Precision
Alderwood Supply's warehouse dashboard shows how long an order sits on the shelf before it ships, one average per aisle. The timing system reports those averages with far more digits than anybody can read across a room, and the dashboard has space for two decimal places. Shortening a number is not the same as cutting the extra digits off the end: an aisle averaging 2.6789 belongs on the board as 2.68, not 2.67.
Task: Print every average kept to two decimal places.
Input
The first line holds an integer n, the count of averages. Each of the next n lines holds one average, written with a decimal point.
Output
One line holding the n shortened averages, separated by single spaces, in the order they were read. Write them the way Python writes a float, which keeps no trailing zeros: an average that comes to exactly 3 shows as 3.0 and one that comes to exactly 1.5 shows as 1.5, never 3.00 or 1.50.
Example:
Input:
3
1.2345
2.6789
3.0001
Output:
1.23 2.68 3.0
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in