Path: blob/master/test/jdk/java/text/Format/DecimalFormat/Bug8165466.java
41152 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 816546625* @summary Checks the subsequent function calls of the DecimalFormat.format()26* method in which the minimumFractionDigit is set to 0 and one of27* the format() call include formatting of the number with zero28* fraction value e.g. 0.00, 9.0029*/3031import java.text.DecimalFormat;32import java.util.Locale;3334public class Bug8165466 {3536public static void main(String[] args) {37DecimalFormat nf = (DecimalFormat) DecimalFormat38.getPercentInstance(Locale.US);39nf.setMaximumFractionDigits(3);40nf.setMinimumFractionDigits(0);41nf.setMultiplier(1);4243double d = 0.005678;44String result = nf.format(d);45if (!result.equals("0.006%")) {46throw new RuntimeException("[Failed while formatting the double"47+ " value: " + d + " Expected: 0.006%, Found: " + result48+ "]");49}5051d = 0.00;52result = nf.format(d);53if (!result.equals("0%")) {54throw new RuntimeException("[Failed while formatting the double"55+ " value: " + d + " Expected: 0%, Found: " + result56+ "]");57}5859d = 0.005678;60result = nf.format(d);61if (!result.equals("0.006%")) {62throw new RuntimeException("[Failed while formatting the double"63+ " value: " + d + " Expected: 0.006%, Found: " + result64+ "]");65}6667//checking with the non zero value68d = 0.005678;69result = nf.format(d);70if (!result.equals("0.006%")) {71throw new RuntimeException("[Failed while formatting the double"72+ " value: " + d + " Expected: 0.006%, Found: " + result73+ "]");74}7576d = 9.00;77result = nf.format(d);78if (!result.equals("9%")) {79throw new RuntimeException("[Failed while formatting the double"80+ " value: " + d + " Expected: 9%, Found: " + result81+ "]");82}8384d = 0.005678;85result = nf.format(d);86if (!result.equals("0.006%")) {87throw new RuntimeException("[Failed while formatting the double"88+ " value: " + d + " Expected: 0.006%, Found: " + result89+ "]");90}91}9293}94959697