// File: FormattedOutput.java // Routines to output variables of type double and int // Field widths are specified in which values are right justified class FormattedOutput { // Given a double Value, this routine will return a string representation // of the number with precision 2 and right justified in a field // of Length spaces. // Precondition: The number of digits necessary to represent Value MUST // be less than or equal to the argument Length public static String DoubleToFormatString(double Value,int Length) {String S=String.valueOf(Value),OutString; char Temp[]=new char[Length]; int i,len=S.length(); // Add .00 to numbers without fractional part if (S.indexOf('.')==-1) { System.out.println("123456789"); S=S+".00"; len+=3; } // Add a 0 to fractional parts of precision 1 else if (len-S.indexOf('.')==2) { len++; Temp[Length-1]='0'; } // Reduce a number with precision > 2 to precision 2 else if (len-S.indexOf('.')>3) { S=S.substring(0,S.indexOf('.')+3); len=S.length(); } // Pad blanks to the left of the value for (i=len;i