public static int toDecimalDigits ( float v , char [ ] digits , int offset , int maxDigits , int maxFractDigits , int roundMode ) { int bits = Float . floatToIntBits ( v ) ; int f = bits & 0x7fffff ; int e = ( bits >> 23 ) & 0xff ; if ( e != 0 ) { // Normalized number. return toDecimalDigits ( f + 0x800000 , e - 126 , 24 , digits , offset , maxDigits , maxFractDigits , roundMode ) ; } else { // Denormalized number. return toDecimalDigits ( f , - 125 , 23 , digits , offset , maxDigits , maxFractDigits , roundMode ) ; } }
Produces decimal digits for non - zero finite floating point values . The sign of the value is discarded . Passing in Infinity or NaN produces invalid digits . The maximum number of decimal digits that this function will likely produce is 9 .