public void doSubstitution ( double number , StringBuilder toInsertInto , int position , int recursionCount ) { if ( ! byDigits ) { // if we're not in "byDigits" mode, just use the inherited // doSubstitution() routine super . doSubstitution ( number , toInsertInto , position , recursionCount ) ; } else { // if we're in "byDigits" mode, transform the value into an integer // by moving the decimal point eight places to the right and // pulling digits off the right one at a time, formatting each digit // as an integer using this substitution's owning rule set // (this is slower, but more accurate, than doing it from the // other end) // just print to string and then use that DigitList dl = new DigitList ( ) ; dl . set ( number , 20 , true ) ; boolean pad = false ; while ( dl . count > Math . max ( 0 , dl . decimalAt ) ) { if ( pad && useSpaces ) { toInsertInto . insert ( position + pos , ' ' ) ; } else { pad = true ; } ruleSet . format ( dl . digits [ -- dl . count ] - ' ' , toInsertInto , position + pos , recursionCount ) ; } while ( dl . decimalAt < 0 ) { if ( pad && useSpaces ) { toInsertInto . insert ( position + pos , ' ' ) ; } else { pad = true ; } ruleSet . format ( 0 , toInsertInto , position + pos , recursionCount ) ; ++ dl . decimalAt ; } } }
If in by digits mode fills in the substitution one decimal digit at a time using the rule set containing this substitution . Otherwise uses the superclass function .