Problem Statement
You have a calculator with a screen that can display up to digits digits along with a single decimal point. If the result of an operation is a number that cannot fit on the screen, the calculator will show just "E" (quotes for clarity) rather than the actual result. Note that fractional numbers less than 1.0 are always shown without the leftmost 0 (for example, ".125"). Also note that integer numbers are never shown with a decimal point, so 4 would always be shown as "4", not "4." or "4.0"." Leading zeros are never displayed (at the left of integer part or the right in the fractional part).
Given a numerator n and denominator d, return the content of the calculator's screen after dividing n by d. For example, 10005 divided by 400 is 25.0125. A 6-digit display would show "25.0125" while a 5-digit display would show "E" (all quotes for clarity only).
Definition
- Class:
- CalculatorDisplay
- Method:
- numberDivision
- Parameters:
- int, int, int
- Returns:
- String
- Method signature:
- String numberDivision(int digits, int n, int d)
- (be sure your method is public)
Constraints
- digits will be between 1 and 20, inclusive.
- n will be between 0 and 1,000,000,000, inclusive.
- d will be between 1 and 1,000,000,000, inclusive.
Examples
10
10005
400
Returns: "25.0125"
The example from the problem statement.
5
10005
400
Returns: "E"
The same result would not fit in only five digits.
10
1
8
Returns: ".125"
5
434544
352
Returns: "1234.5"
Note that the decimal point does not add a position, and the result occupies all of its five digits.
20
1
3
Returns: "E"
To display the result would require an infinite number of fractional digits!
10
1000000000
1
Returns: "1000000000"
9
1000000000
1
Returns: "E"
1
1000000000
1000000000
Returns: "1"
1
0
1000000000
Returns: "0"
20
1
1000000000
Returns: ".000000001"
20
3
1000000000
Returns: ".000000003"
9
3
1000000000
Returns: ".000000003"
10
999999999
1000000000
Returns: ".999999999"
20
465566339
479142415
Returns: "E"
20
57886066
961126156
Returns: "E"
20
17450740
222702061
Returns: "E"
20
72282698
19879756
Returns: "E"
20
58368051
48787573
Returns: "E"
20
560672241
330534376
Returns: "E"
20
774759233
407464967
Returns: "E"
20
358347371
336980169
Returns: "E"
20
266681054
180434859
Returns: "E"
20
449507901
64381965
Returns: "E"
20
66920523
671014631
Returns: "E"
20
29219487
701702729
Returns: "E"
20
83586259
944283356
Returns: "E"
20
927271031
778374505
Returns: "E"
20
524827736
582236637
Returns: "E"
20
61379048
807107663
Returns: "E"
20
620750169
990394076
Returns: "E"
20
65612487
971781471
Returns: "E"
20
991661224
638200911
Returns: "E"
20
539504833
137895186
Returns: "E"
10
8454795
901844800
Returns: ".009375"
20
307483187
635421875
Returns: ".483904"
20
78658538
212720000
Returns: ".369775"
20
369763636
566145280
Returns: ".653125"
20
81260964
866783616
Returns: ".09375"
20
186664307
198579050
Returns: ".94"
20
46242558
83772750
Returns: ".552"
20
5106794
77000000
Returns: ".066322"
20
193946298
2769000
Returns: "70.042"
20
469687830
1104
Returns: "425441.875"
20
563285871
117725000
Returns: "4.78476"
20
305253155
32
Returns: "9539161.09375"
20
628554643
100000
Returns: "6285.54643"
20
61225992
2
Returns: "30612996"
20
502236268
166303400
Returns: "3.02"
20
82964460
375000
Returns: "221.23856"
20
898175151
5868
Returns: "153063.25"
20
129755301
441645000
Returns: ".2938"
20
416382499
203125000
Returns: "2.049883072"
20
191407
625000
Returns: ".3062512"
20
361281258
277908660
Returns: "1.3"
20
292369980
120
Returns: "2436416.5"
20
871243107
192750000
Returns: "4.520068"
20
905588065
652000000
Returns: "1.38893875"
20
942903306
1562500
Returns: "603.45811584"
20
675584109
265247000
Returns: "2.547"
20
990295695
96
Returns: "10315580.15625"
20
105896624
19660000
Returns: "5.3864"
9
999999999
1000000000
Returns: ".999999999"
8
999999999
1000000000
Returns: "E"
13
0
987654321
Returns: "0"
The result is just zero. Note that the decimal point is not shown if the result is an integer.
9
999999999
1000000000
Returns: ".999999999"
1
500000000
1000000000
Returns: ".5"
1
1
1
Returns: "1"
20
999999999
1000000000
Returns: ".999999999"