int (long currentPageNumber, long pageAmount) { int progressValue; if (currentPageNumber == 0) { progressValue = 0; } else if (currentPageNumber == pageAmount - 1) { progressValue = 100; } else { progressValue = (int)(1 + 99 * (currentPageNumber - 1) / (pageAmount - 1 - 1)); // magic formula } return progressValue; }