Quantcast
Channel: How to nicely format floating numbers to string without unnecessary decimal 0's - Stack Overflow
Browsing all 30 articles
Browse latest View live
↧

Answer by Martin Klosi for How to nicely format floating numbers to string...

Here is an answer that actually works (combination of different answers here)public static String removeTrailingZeros(double f){ if(f == (int)f) { return String.format("%d", (int)f); } return...

View Article


Answer by android developer for How to nicely format floating numbers to...

Here are two ways to achieve it. First, the shorter (and probably better) way:public static String formatFloatToString(final float f){ final int i = (int)f; if(f == i) return Integer.toString(i);...

View Article


Answer by kamal for How to nicely format floating numbers to string without...

String s = String.valueof("your int variable");while (g.endsWith("0") && g.contains(".")) { g = g.substring(0, g.length() - 1); if (g.endsWith(".")) { g = g.substring(0, g.length() - 1); }}

View Article

Answer by JasonD for How to nicely format floating numbers to string without...

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:public static String fmt(double d){ if(d == (long) d)...

View Article

Answer by Hiep for How to nicely format floating numbers to string without...

I made a DoubleFormatter to efficiently convert a great numbers of double values to a nice/presentable string:double horribleNumber = 3598945.141658554548844;DoubleFormatter df = new DoubleFormatter(4,...

View Article


Answer by sethu for How to nicely format floating numbers to string without...

The best way to do this is as below:public class Test { public static void main(String args[]){ System.out.println(String.format("%s something", new Double(3.456)));...

View Article

Answer by Kadi for How to nicely format floating numbers to string without...

String s = "1.210000";while (s.endsWith("0")){ s = (s.substring(0, s.length() - 1));}This will make the string to drop the tailing 0-s.

View Article

Answer by Jeremy Slade for How to nicely format floating numbers to string...

String.format("%.2f", value);

View Article


Answer by Pyrolistical for How to nicely format floating numbers to string...

Naw, never mind. The performance loss due to string manipulation is zero.And here's the code to trim the end after %f:private static String trimTrailingZeros(String number) { if(!number.contains("."))...

View Article


How to nicely format floating numbers to string without unnecessary decimal 0's

A 64-bit double can represent integer +/- 253 exactly.Given this fact, I choose to use a double type as a single type for all my types, since my largest integer is an unsigned 32-bit number.But now I...

View Article
Browsing all 30 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>