Linked Questions
67 questions linked to/from How to nicely format floating numbers to string without unnecessary decimal 0's
82 votes
3 answers
177k views
How to remove trailing zeros from a double [duplicate]
For example I need 5.0 to become 5, or 4.3000 to become 4.3.
11 votes
1 answer
8k views
Format float to show decimal places if is not zero java [duplicate]
I need to to show decimal places of a float value only when it is different from zeros. 5.0 should be shown as 5. 7.3 should be shown as 7.3. 9.000003 should be shown as 9.000003. How to format in ...
14 votes
3 answers
30k views
How to remove trailing zero in a String value and remove decimal point [duplicate]
How do I remove trailing zeros in a String value and remove decimal point if the string contains only zeros after the decimal point? I'm using the below code: String string1 = Double.valueOf(a)....
9 votes
3 answers
11k views
Format a double to omit unnecessary ".0" and never round off [duplicate]
I know how to format a double to keep only the available decimal places (DP), up to a certain number of DPs. This example keeps up to 4 DPs. double d = 1.0; DecimalFormat df = new ...
4 votes
2 answers
10k views
Double to String, how to delete 0 after dot [duplicate]
Possible Duplicate: How to nicely format floating types to String? I have number: Double d1=(Double)0; Double d2=(Double)2.2; Double d3=(Double)4; When I use to String, I get 0.0, 2.2, 4.0, but ...
2 votes
2 answers
1k views
Java: set String.format not to display 0 decimal places [duplicate]
Is there a way to set String.format so that it won't display 00 decimals? For example I would like: String.format("%.2f", 12.345d) to display 12.34 but String.format("%.2f", 12.3d) to display 12.3 ...
0 votes
1 answer
4k views
Format number in JasperReports: how to trim zeroes [duplicate]
I got trouble with format number in JasperReports. For example, i have a double value, and i put the format pattern like #,##0.000 Now, with value of number 1.123, i got what i want, but if the value ...
0 votes
3 answers
2k views
displaying float in android without adding trailing zero [duplicate]
I've got a series of float numbers; I want to display them as they are; but while I use String.getValueOf .0 will be added to my numbers ie 10 is shows as 10.0 what should i do to prevent this mess ?
2 votes
3 answers
495 views
Printing double values accordingly in java [duplicate]
I have double values in Java like the following: 2.3422 45.3267 25.0 What I want to print is: 2.34 45.32 25 So I used the following method DecimalFormat form=new DecimalFormat("#0.00"); form.format(...
0 votes
3 answers
770 views
Formatting floating numbers to certain length [duplicate]
I want to limit my numbers to 7 significant figures (I believe this is known as significant digits in American English) with a maximum of 5 decimal places but I am ensure on how to do this. I am ...
0 votes
2 answers
2k views
How to remove trailing zero from a double? [duplicate]
My program is supposed to calculate change: double purchaseAmount = Double.parseDouble(s1); double amountGiven = Double.parseDouble(s2); double change = purchaseAmount - amountGiven; JOptionPane....
0 votes
2 answers
2k views
How to convert double to String and remove all trailing zero behind the point value? [duplicate]
I have looking for the solution around and doing a little workaround here, but can not wrap up all to meet my expectations. For example, I have double values as below double x = 101.00000 double y = ...
0 votes
2 answers
1k views
Showing and not showing dot and decimals in float values? [duplicate]
How can I make a float value to only show the dot and the decimals if they exist. For example show 17 instead of 17.0 but if I have a 17.2 show the dot and the decimals. Thanks!
2 votes
3 answers
375 views
Java:Double Datatype Value Doesn't Give Exact Answer [duplicate]
I'm finding a logarithm of value 1 which is equal to 0 not 0.0. When user enter any point values then it give exact answer. But the problem is Which Value Does Not Consist in points it give the answer ...
-2 votes
3 answers
564 views
Show price - double as Integer depending on its value in TextView - Android [duplicate]
I would like to know how can I show in my TextView the price as follows: Price is a double value. a=8.75 and b=9.00 I need display a=8.75 and b=9. I supose I need to check something and change its ...