How to nicely format floating numbers to String without unnecessary decimal 0?

Answer

If the idea is to print integers stored as doubles as if they are integers, and otherwise print the doubles with the minimum necessary precision:

publicstaticString fmt(double d){if(d ==(long) d)returnString.format("%d",(long)d);elsereturnString.format("%s",d);}

Produces:

2320.1812378751924.5801.2345

And does not rely on string manipulation.

All string Questions

Ask your interview questions on string

Write Your comment or Questions if you want the answers on string from string Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---