i am new to the java, iam facing an issue in my task with DecimalFormat
when i give integer number it should not have any decimals, if i give decimal number it should print decimal value
i used the DecimalFormater as below
DecimalFormat decimalFormat = (DecimalFormat) NumberFormat.getNumberInstance();
decimalFormat.setMaximumFractionDigits(2);
decimalFormat.applyPattern("0");
System.out.println(decimalFormat.format(123456789.2569));
here it is printing without decimals. i replace my patern with decimalFormat.applyPattern("#.##");
in this case when i give 299 it is printing 3
but it should print 299 how to do it?
finally, if i give 265 it should be 265, if i give 265.36 it should be 265.36
Aucun commentaire:
Enregistrer un commentaire