You just need to use the mod operator on your percentComplete calculation.
int chaptersRead = 1500;
int chaptersInBook = 1189;
System.out.println("total percent read = "+(chaptersRead/(float)chaptersInBook*100f));
// with mod operation to reduce to percent complete for the current reading
float percentOfBook = (chaptersRead/(float)chaptersInBook*100f) % 100f;
System.out.println("percentOfBook = "+percentOfBook);
// or a variation on the same calc
percentOfBook = (chaptersRead%chaptersInBook) / (float)chaptersInBook * 100f;
System.out.println("percentOfBook = "+percentOfBook);
Please use code tags when you post code like this, as it will make it much more readable with the formatting preserved. You should also consider making your variable names more clear instead of using abbreviations. It will help your own clarity of the program as well as others who are reading it.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Offline 6,761 posts
since May 2007