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
119
votes
5 answers

How to print a double with two decimals in Android?

Maybe this is a silly question, but I cannot guess how to solve it if it's not creating a method. Maybe there's a "natural way" to do it, like in C for example. Here's the problem: I have a var: double a; And I want to show it only with 2 or 3…
ArcDare
  • 3,106
  • 4
  • 27
  • 38
114
votes
3 answers

C# 6 how to format double using interpolated string?

I have used interpolated strings for messages containing string variables like $"{EmployeeName}, {Department}". Now I want to use an interpolated string for showing a formatted double. Example var aNumberAsString =…
MagB
  • 2,131
  • 5
  • 28
  • 54
110
votes
7 answers

In java, is it more efficient to use byte or short instead of int and float instead of double?

I've noticed I've always used int and doubles no matter how small or big the number needs to be. So in java, is it more efficient to use byte or short instead of int and float instead of double? So assume I have a program with plenty of ints and…
DisibioAaron
  • 1,342
  • 3
  • 11
  • 17
105
votes
9 answers

How to make C++ cout not use scientific notation

double x = 1500; for(int k = 0; k<10 ; k++){ double t = 0; for(int i=0; i<12; i++){ t += x * 0.0675; x += x * 0.0675; } cout<<"Bas ana: "<
Yunus Eren Güzel
  • 3,018
  • 11
  • 36
  • 63
103
votes
10 answers

Convert double to float in Java

I am facing an issue related to converting double to float. Actually, I store a float type, 23423424666767, in a database, but when we get data from the database in the below code, getInfoValueNumeric(), it's of double type. The value we get is in…
Sitansu
  • 3,225
  • 8
  • 34
  • 61
103
votes
6 answers

How many double numbers are there between 0.0 and 1.0?

This is something that's been on my mind for years, but I never took the time to ask before. Many (pseudo) random number generators generate a random number between 0.0 and 1.0. Mathematically there are infinite numbers in this range, but double is…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
102
votes
1 answer

Set precision of std::to_string when converting floating point values

In C++11, std::to_string defaults to 6 decimal places when given an input value of type float or double. What is the recommended, or most elegant, method for changing this precision?
learnvst
  • 15,455
  • 16
  • 74
  • 121
102
votes
9 answers

Convert double to BigDecimal and set BigDecimal Precision

In Java, I want to take a double value and convert it to a BigDecimal and print out its String value to a certain precision. import java.math.BigDecimal; public class Main { public static void main(String[] args) { double d=-.00012; …
c12
  • 9,557
  • 48
  • 157
  • 253
101
votes
6 answers

How do I get DOUBLE_MAX?

AFAIK, C supports just a few data types: int, float, double, char, void enum. I need to store a number that could reach into the high 10 digits. Since I'm getting a low 10 digit # from INT_MAX , I suppose I need a double. doesn't have…
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
100
votes
7 answers

0.1 float is greater than 0.1 double. I expected it to be false

Let: double d = 0.1; float f = 0.1; should the expression (f > d) return true or false? Empirically, the answer is true. However, I expected it to be false. As 0.1 cannot be perfectly represented in binary, while double has 15 to 16 decimal…
Hesham Eraqi
  • 2,444
  • 4
  • 23
  • 45
99
votes
6 answers

How to find max value for Double and Float in Swift

Current learning Swift, there are ways to find max and min value for different kind of Integer like Int.max and Int.min. Is there a way to find max value for Double and Float? Moreover, which document should I refer for this kind of question? I am…
XY L
  • 25,431
  • 14
  • 84
  • 143
99
votes
5 answers

Converting string to double in C#

I have a long string with double-type values separated by # -value1#value2#value3# etc I splitted it to string table. Then, I want to convert every single element from this table to double type and I get an error. What is wrong with type-conversion…
whoah
  • 4,363
  • 10
  • 51
  • 81
98
votes
9 answers

Moving decimal places over in a double

So I have a double set to equal 1234, I want to move a decimal place over to make it 12.34 So to do this I multiply .1 to 1234 two times, kinda like this double x = 1234; for(int i=1;i<=2;i++) { x = x*.1; } System.out.println(x); This will print…
BlackCow
  • 1,437
  • 2
  • 14
  • 11
98
votes
8 answers

How to check if a double value has no decimal part

I have a double value which I have to display at my UI. Now the condition is that the decimal value of double = 0 eg. - 14.0 In that case I have to show only 14 on my UI. Also, the max limit for characters is 5 here. eg.- 12.34 the integer value…
Ankit
  • 4,426
  • 7
  • 45
  • 62
96
votes
7 answers

Storing statistical data, do I need DECIMAL, FLOAT or DOUBLE?

I am creating for fun, but I still want to approach it seriously, a site which hosts various tests. With these tests I hope to collect statistical data. Some of the data will include the percentage of the completeness of the tests as they are timed.…
PEPLOVE
  • 1,117
  • 1
  • 8
  • 9