private final void round ( int maximumDigits ) { // Eliminate digits beyond maximum digits to be displayed. // Round up if appropriate. if ( maximumDigits >= 0 && maximumDigits < count ) { if ( shouldRoundUp ( maximumDigits ) ) { // Rounding up involved incrementing digits from LSD to MSD. // In most cases this is simple, but in a worst case situation // (9999..99) we have to adjust the decimalAt value. for ( ; ; ) { -- maximumDigits ; if ( maximumDigits < 0 ) { // We have all 9's, so we increment to a single digit // of one and adjust the exponent. digits [ 0 ] = ' ' ; ++ decimalAt ; maximumDigits = 0 ; // Adjust the count break ; } ++ digits [ maximumDigits ] ; if ( digits [ maximumDigits ] <= ' ' ) break ; // digits[maximumDigits] = '0'; // Unnecessary since we'll truncate this } ++ maximumDigits ; // Increment for use as count } count = maximumDigits ; // Eliminate trailing zeros. while ( count > 1 && digits [ count - 1 ] == ' ' ) { -- count ; } } }
Round the representation to the given number of digits .