Questions tagged [double]

Double is a primitive data type used to store fractional numbers that holds a double-precision floating-point (often 64 bits).

In C and C++ double must be at least as large as float (another floating-point type), but its actual size can vary from system to system as it is implementation-defined. It is typically twice the size of float. Many systems store doubles in binary64, a format described in the IEEE 754 technical standard.

Java has a very strict definition for double, requiring it to be stored in binary64 (which is also called double-precision).

More information:

8301 questions
2419
votes
18 answers

Difference between decimal, float and double in .NET?

What is the difference between decimal, float and double in .NET? When would someone use one of these?
Tom
997
votes
7 answers

decimal vs double! - Which one should I use and when?

I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision. My question is when should a use a double and when should I use a decimal type? Which type is suitable for money computations? (ie. greater…
Soni Ali
  • 18,464
  • 16
  • 44
  • 53
800
votes
13 answers

How to convert Decimal to Double in C#?

I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal trans = trackBar1.Value / 5000; this.Opacity = trans; When I build the app it gives the following error: Cannot implicitly convert type decimal to double
Eggs McLaren
  • 1,777
  • 3
  • 12
  • 13
610
votes
29 answers

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 have to print these pseudo integers, but the…
Pyrolistical
  • 27,624
  • 21
  • 81
  • 106
593
votes
13 answers

Round a double to 2 decimal places

If the value is 200.3456, it should be formatted to 200.34. If it is 200, then it should be 200.00.
Rajesh
  • 8,477
  • 5
  • 20
  • 7
590
votes
5 answers

Why does Math.round(0.49999999999999994) return 1?

In the following program you can see that each value slightly less than .5 is rounded down, except for 0.5. for (int i = 10; i >= 0; i--) { long l = Double.doubleToLongBits(i + 0.5); double x; do { x =…
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
584
votes
5 answers

Correct format specifier for double in printf

What is the correct format specifier for double in printf? Is it %f or is it %lf? I believe it's %f, but I am not sure. Code sample #include int main() { double d = 1.4; printf("%lf", d); // Is this wrong? }
Leopard
  • 5,851
  • 3
  • 15
  • 4
543
votes
35 answers

Rounding a double value to x number of decimal places in swift

Can anyone tell me how to round a double value to x number of decimal places in Swift? I have: var totalWorkTimeInHours = (totalWorkTime/60/60) With totalWorkTime being an NSTimeInterval (double) in second. totalWorkTimeInHours will give me the…
Leighton
  • 6,559
  • 7
  • 21
  • 28
414
votes
21 answers

Checking if a double (or float) is NaN in C++

Is there an isnan() function? PS.: I'm in MinGW (if that makes a difference). I had this solved by using isnan() from , which doesn't exist in , which I was #includeing at first.
hasen
  • 161,647
  • 65
  • 194
  • 231
413
votes
7 answers

Double vs. BigDecimal?

I have to calculate some floating point variables and my colleague suggest me to use BigDecimal instead of double since it will be more precise. But I want to know what it is and how to make most out of BigDecimal?
Truong Ha
  • 10,468
  • 11
  • 40
  • 45
369
votes
9 answers

How can I divide two integers to get a double?

How do I divide two integers to get a double?
leora
  • 188,729
  • 360
  • 878
  • 1,366
346
votes
8 answers

Round double in two decimal places in C#?

I want to round up double value in two decimal places in c# how can i do that? double inputValue = 48.485; after round up inputValue = 48.49; Related: c# - How do I round a decimal value to 2 decimal places (for output on a page)
sanjeev40084
  • 9,227
  • 18
  • 67
  • 99
327
votes
14 answers

Convert String to double in Java

How can I convert a String such as "12.34" to a double in Java?
TinyBelly
  • 3,337
  • 3
  • 17
  • 7
315
votes
7 answers

How do you test to see if a double is equal to NaN?

I have a double in Java and I want to check if it is NaN. What is the best way to do this?
Eric Wilson
  • 57,719
  • 77
  • 200
  • 270
304
votes
18 answers

How do I print a double value without scientific notation using Java?

I want to print a double value in Java without exponential form. double dexp = 12345678; System.out.println("dexp: "+dexp); It shows this E notation: 1.2345678E7. I want it to print it like this: 12345678 What is the best way to prevent this?
Despicable
  • 3,797
  • 3
  • 24
  • 42
1
2 3
99 100