I have the following class
public class Foo {
   private long var1;
   private float var2;
   private double var3;
   /* getter and setter
    */
}
To print a numeric value to command line, I use String.valueOf(obj.getVar2()), but this will result in 9.888888888. Are there any ways, to produce formatted outputs for all numeric getters (float, double)? I have a function 'bar' , which will format a given numeric value to a string. Now, I want to call functions like obj.getVar2().toString(), to get the numeric value back as a formatted string from 'bar'. Is it possible?