public static String fancyStringF ( double value , DecimalFormat format , int length , int significant ) { String formatted = fancyString ( value , format , length , significant ) ; int n = length - formatted . length ( ) ; if ( n > 0 ) { StringBuilder builder = new StringBuilder ( n ) ; for ( int i = 0 ; i < n ; i ++ ) { builder . append ( ' ' ) ; } return formatted + builder . toString ( ) ; } else { return formatted ; } }
Fixed length fancy formatting for doubles . If possible decimal notation is used . If all the significant digits can t be shown then it will switch to exponential notation . If not all the space is needed then it will be filled in to ensure it has the specified length .