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:

7762 questions
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,253
  • 3
  • 20
  • 40
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,398
  • 2
  • 13
  • 11
97
votes
6 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,202
  • 2
  • 11
  • 17
95
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
  • 348,637
  • 121
  • 546
  • 611
94
votes
12 answers

Round up double to 2 decimal places

How do I round up currentRatio to two decimal places? let currentRatio = Double (rxCurrentTextField.text!)! / Double (txCurrentTextField.text!)! railRatioLabelField.text! = "\(currentRatio)"
Del Hinds
  • 2,257
  • 3
  • 9
  • 12
86
votes
2 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
  • 1,781
  • 4
  • 23
  • 51
83
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
  • 2,935
  • 5
  • 28
  • 55
82
votes
8 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
  • 2,699
  • 9
  • 34
  • 58
81
votes
3 answers

What is the max. value of a double/float on iOS?

What are the values of a double/float on iOS, or the file that they're defined in? Or a macro, like INT_MAX?
tadejsv
  • 1,938
  • 1
  • 15
  • 19
80
votes
11 answers

Double.TryParse or Convert.ToDouble - which is faster and safer?

My application reads an Excel file using VSTO and adds the read data to a StringDictionary. It adds only data that are numbers with a few digits (1000 1000,2 1000,34 - comma is a delimiter in Russian standards). What is better to check if the…
abatishchev
  • 92,232
  • 78
  • 284
  • 421
80
votes
7 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…
X.Creates
  • 11,800
  • 7
  • 58
  • 98
80
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
  • 13,927
  • 13
  • 65
  • 108
80
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
  • 3,614
  • 7
  • 38
  • 58
79
votes
7 answers

How to cast from List to double[] in Java?

I have a variable like that: List frameList = new ArrayList(); /* Double elements has added to frameList */ How can I have a new variable has a type of double[] from that variable in Java with high performance?
kamaci
  • 65,625
  • 65
  • 210
  • 342
79
votes
6 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
  • 937
  • 1
  • 6
  • 8