public String penniesToDollars ( int pennies ) { float decimal = pennies / 100f ; // if the pennies is a whole number of dollars, then we return just the string number if ( pennies % 100 == 0 ) { return String . format ( "%.0f" , decimal ) ; } // otherwise we always return two decimal places return String . format ( "%#.2f" , decimal ) ; }
Velocity currently doesn t support floats so we have to provide our own support to convert pennies to a dollar amount .