Just use String.format:
System.out.println(String.format("%.2f",ans));
Note that this converts your value into a String, for calculations you should keep using its numeric representation.
solved How to limit decimals digits?
Just use String.format:
System.out.println(String.format("%.2f",ans));
Note that this converts your value into a String, for calculations you should keep using its numeric representation.
solved How to limit decimals digits?