fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone{
  9.  
  10. public static void main(String []args){
  11. System.out.println(trimDecimalValues1(32.24, "2s"));
  12. }
  13.  
  14. public static String trimDecimalValues1(Double value,String prec) {
  15. String retval = "";
  16. try{
  17. retval=String.format("%."+prec+"f", value);
  18.  
  19. }catch(Exception e){
  20. retval=String.format("%.2f", value);
  21.  
  22. }finally{
  23. if(retval.equals(".00")){
  24. retval="0.00";
  25. }
  26. return retval;
  27. }
  28. }
  29. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
32f