Fix logic in if-else statement

Use the < operator instead of <= to capture every number without gaps.
Declare variables where they are used and remove DecimalFormat.