Doubty of DecimalFormat

zhaozj2021-02-16  84

A process a few days ago, to format the most 5 decimal data, the format of the output required to output "There are several decimals display a few digits, can not use the scientific counting method" Formatted with Decimalformat, formatted mode "0. #####", but for float a = 1234.22f, always formatting is wrong, is inexplicably formatted to 1234.21997, I wrote a small test program below: public static void main (String [] AGRS ) {Decimalformat df = new decimalformat ("0. #####"); float a = 12345.22f; float b = 1234.22F; float c = 123.22F; float d = 0.123456789f; Double E = 123456789.22; system. Out.println ("before formation"); system.out.println (a); system.out.println (b); system.out.println (c); system.out.println (d); system.out. Println (E);

转载请注明原文地址:https://www.9cbs.com/read-12216.html

New Post(0)