Linked Questions
67 questions linked to/from How to nicely format floating numbers to string without unnecessary decimal 0's
10 votes
4 answers
32k views
Remove trailing zeros from double
I would like to remove all trailing zeros without truncating or rounding the number if it doesn't have any. For example, the number could be something like 12.0, in which case, the trailing zero ...
7 votes
1 answer
18k views
Float Precision Display (Android)
I am trying to make a program that takes some user input, runs a few calculations and outputs the answer. My problem is that this answer is sometimes many decimal places long which is causing some ...
10 votes
6 answers
22k views
C# How to nicely format floating numbers to String without unnecessary decimal 0?
I have the same problem as HERE, but I'm using C#, How to do it in C#? (if use Tostring("F") as Here, all float number will turn into X.XX, also 0 to 0.00) Here's an example float numbers 232....
11 votes
5 answers
9k views
Format float to maximum N decimal places
I'd like to format a number to maximum N decimal places. There's another similar and popular question here, but that's not exactly what I'm looking for. I'm looking for something like this, let's say ...
14 votes
5 answers
17k views
How to retain trailing zeroes when converting BigDecimal to String
I have to convert a BigDecimal value, e.g. 2.1200, coming from the database to a string. When I use the toString() or toPlainString() of BigDecimal, it just prints the value 2.12 but not the trailing ...
2 votes
7 answers
20k views
Java: How to concatenate Double to String
How can i concatenate Double to String in java? I have following piece of code: Double price = 5.34; String trade = MSFT; now I have String key = price + trade, not sure if this is right way of ...
0 votes
6 answers
6k views
How can I remove the ".0" from a double? Android Studio
I'm making a calculator for Android but I have a problem with the double. When I write a operation like 2+2 the result is 4.0 instead of 4 . How can I remove the ".0" from the result? This is my ...
0 votes
3 answers
4k views
How to make NumberFormat returns in double-type [duplicate]
The function below works perfectly, but I would like to make it to return the value in double format, as the function below return the value in String format. private static String convertMoneyToSap(...
1 vote
2 answers
5k views
How to format a float number in java String.ValueOf
I have this code: StringBuilder sbp = new StringBuilder().append( String.valueOf((temp / 10F))) .append(" \260C / ").append(String.valueOf((temp/10F)*9/5+32)) .append(" \260F"); and I get ...
8 votes
2 answers
5k views
DecimalFormat - keep all decimal numbers
I'm using DecimalFormat to format doubles into a String. This String is then integrated into my presentation layer. Problem: I want to keep ALL decimals. Example: "12345678.123456789" Question: What ...
0 votes
3 answers
4k views
String cannot be converted to double
I am trying to make a calculator with Java, and everything worked normally until this error popped up: imcompatible types: String cannot be converted to double Invalid value type 'String' for ...
1 vote
4 answers
3k views
How to remove decimal places if zeros are present [duplicate]
I want to remove zeroes from my string as decimal places, but I am not able to do that. Also, I want the decimal places gone only if zeros are there else the decimal places will be there. Example: ...
1 vote
2 answers
6k views
Remove trailing zeroes after decimal from double
I am writing a program to get the average of two numbers. For test case, 2, 4 the output should be 3 not 3.0. For test case, -1282660896, -672813783 the output should be -977737339.5 not -9....
3 votes
1 answer
3k views
Remove trailing zeros in float representation
Declaring a variable of this form %.2f what I want is to have maximum 2 digits after decimal point. As it is now, it shows only two as expected, I would like to have also the trailing zeros removed. ...
1 vote
3 answers
2k views
How to set in Java a custom number of decimal digits in float or double with approximation [duplicate]
Possible Duplicate: How to round a number to n decimal places in Java I want to set a specified number of decimal digits in a float (or double), with a method in this form public float ...