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 package test.java.text.Format.DecimalFormat; 33 34 import java.text.DecimalFormat; 35 import java.util.Locale; 36 37 public class Bug8165466 { 38 main(String[] args)39 public static void main(String[] args) { 40 DecimalFormat nf = (DecimalFormat) DecimalFormat 41 .getPercentInstance(Locale.US); 42 nf.setMaximumFractionDigits(3); 43 nf.setMinimumFractionDigits(0); 44 nf.setMultiplier(1); 45 46 double d = 0.005678; 47 String result = nf.format(d); 48 if (!result.equals("0.006%")) { 49 throw new RuntimeException("[Failed while formatting the double" 50 + " value: " + d + " Expected: 0.006%, Found: " + result 51 + "]"); 52 } 53 54 d = 0.00; 55 result = nf.format(d); 56 if (!result.equals("0%")) { 57 throw new RuntimeException("[Failed while formatting the double" 58 + " value: " + d + " Expected: 0%, Found: " + result 59 + "]"); 60 } 61 62 d = 0.005678; 63 result = nf.format(d); 64 if (!result.equals("0.006%")) { 65 throw new RuntimeException("[Failed while formatting the double" 66 + " value: " + d + " Expected: 0.006%, Found: " + result 67 + "]"); 68 } 69 70 //checking with the non zero value 71 d = 0.005678; 72 result = nf.format(d); 73 if (!result.equals("0.006%")) { 74 throw new RuntimeException("[Failed while formatting the double" 75 + " value: " + d + " Expected: 0.006%, Found: " + result 76 + "]"); 77 } 78 79 d = 9.00; 80 result = nf.format(d); 81 if (!result.equals("9%")) { 82 throw new RuntimeException("[Failed while formatting the double" 83 + " value: " + d + " Expected: 9%, Found: " + result 84 + "]"); 85 } 86 87 d = 0.005678; 88 result = nf.format(d); 89 if (!result.equals("0.006%")) { 90 throw new RuntimeException("[Failed while formatting the double" 91 + " value: " + d + " Expected: 0.006%, Found: " + result 92 + "]"); 93 } 94 } 95 96 } 97 98