Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/DecimalFormat/Bug8165466.java
41152 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
/*
24
* @test
25
* @bug 8165466
26
* @summary Checks the subsequent function calls of the DecimalFormat.format()
27
* method in which the minimumFractionDigit is set to 0 and one of
28
* the format() call include formatting of the number with zero
29
* fraction value e.g. 0.00, 9.00
30
*/
31
32
import java.text.DecimalFormat;
33
import java.util.Locale;
34
35
public class Bug8165466 {
36
37
public static void main(String[] args) {
38
DecimalFormat nf = (DecimalFormat) DecimalFormat
39
.getPercentInstance(Locale.US);
40
nf.setMaximumFractionDigits(3);
41
nf.setMinimumFractionDigits(0);
42
nf.setMultiplier(1);
43
44
double d = 0.005678;
45
String result = nf.format(d);
46
if (!result.equals("0.006%")) {
47
throw new RuntimeException("[Failed while formatting the double"
48
+ " value: " + d + " Expected: 0.006%, Found: " + result
49
+ "]");
50
}
51
52
d = 0.00;
53
result = nf.format(d);
54
if (!result.equals("0%")) {
55
throw new RuntimeException("[Failed while formatting the double"
56
+ " value: " + d + " Expected: 0%, Found: " + result
57
+ "]");
58
}
59
60
d = 0.005678;
61
result = nf.format(d);
62
if (!result.equals("0.006%")) {
63
throw new RuntimeException("[Failed while formatting the double"
64
+ " value: " + d + " Expected: 0.006%, Found: " + result
65
+ "]");
66
}
67
68
//checking with the non zero value
69
d = 0.005678;
70
result = nf.format(d);
71
if (!result.equals("0.006%")) {
72
throw new RuntimeException("[Failed while formatting the double"
73
+ " value: " + d + " Expected: 0.006%, Found: " + result
74
+ "]");
75
}
76
77
d = 9.00;
78
result = nf.format(d);
79
if (!result.equals("9%")) {
80
throw new RuntimeException("[Failed while formatting the double"
81
+ " value: " + d + " Expected: 9%, Found: " + result
82
+ "]");
83
}
84
85
d = 0.005678;
86
result = nf.format(d);
87
if (!result.equals("0.006%")) {
88
throw new RuntimeException("[Failed while formatting the double"
89
+ " value: " + d + " Expected: 0.006%, Found: " + result
90
+ "]");
91
}
92
}
93
94
}
95
96
97