Problem Statement
Hence, the traditional rounding method described in the opening sentence would be represented by cutoff = "0.5000"
Definition
- Class:
- CutoffRounder
- Method:
- round
- Parameters:
- String, String
- Returns:
- int
- Method signature:
- int round(String num, String cutoff)
- (be sure your method is public)
Constraints
- cutoff will be formatted exactly as "0.####", where each '#' represents a digit ('0'-'9').
- num will be a sequence of one or more digits ('0'-'9'), with an optional decimal point ('.').
- num will contain between 1 and 10 characters, inclusive.
- The fractional part of num will not be exactly equal to cutoff.
- num will be between 0 and 2,000,000,000, inclusive.
Examples
"003.656930"
"0.5000"
Returns: 4
0.65693 is greater than 0.5000, so we round up.
".001"
"0.0001"
Returns: 1
A very low cutoff.
"1.99999999"
"0.9999"
Returns: 2
"135"
"0.6531"
Returns: 135
"135."
"0.6531"
Returns: 135
"1356.13671"
"0.1367"
Returns: 1357
"0.00010001"
"0.0001"
Returns: 1
"8.09871845"
"0.7686"
Returns: 8
"3.08395116"
"0.0644"
Returns: 4
"5.92313529"
"0.4448"
Returns: 6
"2.78002571"
"0.6646"
Returns: 3
"2.06727476"
"0.6701"
Returns: 2
"4.12000643"
"0.9880"
Returns: 4
"7.00141667"
"0.0378"
Returns: 7
"4.01010601"
"0.1206"
Returns: 4
"3.37102613"
"0.7196"
Returns: 3
"6.07413963"
"0.2014"
Returns: 6
"6.95004621"
"0.7310"
Returns: 7
"3.23409438"
"0.5293"
Returns: 3
"1.10098438"
"0.6938"
Returns: 1
"7.92270291"
"0.5631"
Returns: 8
"5.41414392"
"0.2424"
Returns: 6
"4.27141959"
"0.8894"
Returns: 4
"9.17186083"
"0.2145"
Returns: 9
"2.42622954"
"0.0441"
Returns: 3
"6.32255295"
"0.7484"
Returns: 6
"1.88850429"
"0.7432"
Returns: 2
"6.02679408"
"0.3743"
Returns: 6
"5.39233266"
"0.6461"
Returns: 5
"9.27097782"
"0.3541"
Returns: 9
"7.45833598"
"0.3319"
Returns: 8
"1.10892893"
"0.6692"
Returns: 1
"1.29535300"
"0.2227"
Returns: 2
"1.57579983"
"0.1045"
Returns: 2
"4.02989128"
"0.1629"
Returns: 4
"5.99280642"
"0.8032"
Returns: 6
"5.88131910"
"0.9851"
Returns: 5
"0.44"
"0.5000"
Returns: 0
".0005"
"0.5000"
Returns: 0
".001"
"0.0001"
Returns: 1
"135"
"0.6531"
Returns: 135
"1.000001"
"0.0001"
Returns: 1
"1000000"
"0.0001"
Returns: 1000000
"3.0002"
"0.5000"
Returns: 3
"0.012"
"0.0210"
Returns: 0