Linked Questions

10 votes
4 answers
32k views

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 ...
Mohit Deshpande's user avatar
7 votes
1 answer
18k views

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 ...
Tom C's user avatar
  • 242
10 votes
6 answers
22k views

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....
yu yang Jian's user avatar
  • 7,293
11 votes
5 answers
9k views

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 ...
mac's user avatar
  • 2,734
14 votes
5 answers
17k views

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 ...
user68883's user avatar
  • 838
2 votes
7 answers
20k views

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 ...
Rachel's user avatar
  • 104k
0 votes
6 answers
6k views

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 ...
Aquila's user avatar
  • 23
0 votes
3 answers
4k views

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(...
mrjimoy_05's user avatar
  • 3,588
1 vote
2 answers
5k views

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 ...
Mario's user avatar
  • 15k
8 votes
2 answers
5k views

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 ...
Dimitri Dewaele's user avatar
0 votes
3 answers
4k views

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 ...
Timppa's user avatar
  • 363
1 vote
4 answers
3k views

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: ...
Areeb Khan's user avatar
1 vote
2 answers
6k views

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....
Jainendra's user avatar
  • 25.2k
3 votes
1 answer
3k views

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. ...
Leo Messi's user avatar
  • 6,360
1 vote
3 answers
2k views

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 ...
AndreaF's user avatar
  • 12.5k

15 30 50 per page