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

Converting double to string with N decimals, dot as decimal separator, and no thousand separator

I need to convert a decimal to a string with N decimals (two or four) and NO thousand separator: 'XXXXXXX (dot) DDDDD' The problem with CultureInfo.InvariantCulture is that is places ',' to separate thousands. UPDATE This should work for decimal and…
Captain Comic
  • 15,744
  • 43
  • 110
  • 148
87
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
  • 72,915
  • 69
  • 228
  • 366
87
votes
7 answers

How to change symbol for decimal point in double.ToString()?

I would like to change decimal point to another character in C#. I have a double variable value double value; and when I use the command: Console.WriteLine(value.ToString()); // output is 1,25 I know I can do…
MartyIX
  • 27,828
  • 29
  • 136
  • 207
86
votes
6 answers

Java double vs BigDecimal for latitude/longitude

When storing latitudes/longitudes which are typically of the format: 44.087585 (i.e. max 2 numbers before the dot and 6dp) do I need to bother with bigdecimals?
DD.
  • 21,498
  • 52
  • 157
  • 246
86
votes
6 answers

Random weighted selection in Java

I want to choose a random item from a set, but the chance of choosing any item should be proportional to the associated weight Example inputs: item weight ---- ------ sword of misery 10 shield of happy …
yosi
  • 887
  • 1
  • 8
  • 5
85
votes
5 answers

Round to nearest five

I need to round a double to nearest five. I can't find a way to do it with the Math.Round function. How can I do this? What I want: 70 = 70 73.5 = 75 72 = 70 75.9 = 75 69 = 70 and so on.. Is there an easy way to do this?
Martin
  • 2,269
  • 3
  • 19
  • 10
84
votes
5 answers

DOUBLE vs DECIMAL in MySQL

OK, so I know there are tons of articles stating I shouldn't use DOUBLE to store money on a MySQL database, or I'll end up with tricky precision bugs. The point is I am not designing a new database, I am ask to find way to optimise an existing…
user327961
  • 2,440
  • 3
  • 22
  • 20
82
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
  • 2,085
  • 1
  • 18
  • 20
81
votes
2 answers

Why does Math.ceil return a double?

When I call Math.ceil(5.2) the return is the double 6.0. My natural inclination was to think that Math.ceil(double a) would return a long. From the documentation: ceil(double a) Returns the smallest (closest to negative infinity) double value …
PengOne
  • 48,188
  • 17
  • 130
  • 149
81
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
  • 98,240
  • 88
  • 296
  • 433
79
votes
18 answers

Comparing double values in C#

I've a double variable called x. In the code, x gets assigned a value of 0.1 and I check it in an 'if' statement comparing x and 0.1 if (x==0.1) { ---- } Unfortunately it does not enter the if statement Should I use Double or double? What's the…
stack_pointer is EXTINCT
  • 2,263
  • 12
  • 49
  • 59
78
votes
7 answers

Could not cast value of type 'NSTaggedPointerString' to 'NSNumber'

I have a Swift struct like this. struct Usage { var totalData: Double var remainingTotalData: Double init(jsonData: NSData) { var jsonDict = [String: AnyObject]() do { jsonDict = try…
Isuru
  • 30,617
  • 60
  • 187
  • 303
76
votes
3 answers

How to remove trailing zeros from a double

For example I need 5.0 to become 5, or 4.3000 to become 4.3.
Wrath
  • 825
  • 1
  • 6
  • 6
75
votes
3 answers

Unsigned double in C++?

Why doesn't C++ support unsigned double syntax?
lost3den
  • 815
  • 1
  • 6
  • 6
74
votes
5 answers

How to cast the size_t to double or int C++

My question is that I have a size_t data, but now I want to convert it to double or int. If I do something like size_t data = 99999999; int convertdata = data; the compiler will report warning. because it maybe overflow. Do you have some method…
user2701639
  • 861
  • 2
  • 8
  • 13