Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+12 votes

I there a way round off the decimals so that you don't get any zero after the decimal point? I don't know how to get printf to do it because it rounds off to a fixed number of digits after the decimal points.

Specifically in this

System.out.printf("%s's grade is %.1f", name, avg);

Let's say: 77.250 and 14.50 could be the value of avg, how do I make 77.250 --> 77.25 and 14.50 --> 14.5 at the same time?

asked in CSC211_Winter2018 by (1 point)

1 Answer

+10 votes
 
Best answer

Never mind I got figured it out. If avg*100 is divided by 10 doesn't have any remainder, then 1 decimal.

Let me know if there's a better way!

answered by (1 point)
selected by
...