double

problem in comparing double values in C#

hi i'm using C# with visual studio... I've a double variable called x. in the code written x gets assigned a value of 0.1 to it and i check it in an 'if' sttment comapring x and 0.1 if(x==0.1) { ---- } Unfortunately it doesnot enter the if sttment :( ... 1) Should i use Double or double??? 2) wat's the reason behind this?.. Can u...

C : erroneous output for "(long long int) = (long long int) * (double)"?

long long int A = 3289168178315264; long long int B = 1470960727228416; double D = sqrt(5); long long int out = A + B*D; printf("%lld",out); This gives result : -2147483648 I am not able to figure out why (it should be a positive result). Can somebody help? ...

Converting float to double

How expensive is the conversion of a float to a double? Is it as trivial as an int to long conversion? EDIT: I'm assuming a platform where where float is 4 bytes and double is 8 bytes ...

How to print a double with a comma

In C++ I've got a float/double variable. when I print this with for example cout the resulting string is period-delimited. cout << 3.1415 << endl $> 3.1415 Is there an easy way to force the double to be printed with a comma? cout << 3.1415 << endl $> 3,1415 ...

Which sql server data type best represents a double in C#?

Is it money, float, real, decimal, _____ ? ...

Java double initialization

In what way are these statements different? double dummy = 0; double dummy = 0.0; double dummy = 0.0d; double dummy = 0.0D; ...

Java - Need help with this.

This is for a friend of mine who is having trouble with Java for school. I do know some programming, but not Java. Scanner kbReader = new Scanner(System.in); System.out.print("Name of item: "); String name = kbReader.next(); System.out.println("Original price of item: $"); double price = kbReader.nextDouble(); Outputs: Name of item:...

Regex line by line: How to match triple quotes but not double quotes

I need to check to see if a string of many words / letters / etc, contains only 1 set of triple double-quotes (i.e. """), but can also contain single double-quotes (") and double double-quotes (""), using a regex. Haven't had much success thus far. ...

Using iPhone/Objective C CGFloats: Is 0.1 okay, or should it be 0.1f?

Hi there, When using an iPhone Objective C method that accepts CGFloats, e.g. [UIColor colorWithRed:green:blue:], is it important to append a f to constant arguments to specifiy them explicitly as floats, e.g. should I always type 0.1f rather than 0.1 in such cases? Or does the compiler automatically cast 0.1 (which is a double in gener...

Round to nearest five C#

Hi! I'm using C# and 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? ...

How to divide two doubles accurately

I have two double a, b; I know that the following is true -1 <= a/b <= 1 however b can be arbitrarily small. When I do this naively and just compute the value a/b the condition specified above does not hold in some cases and I get values like much greater than 1 in absolute value (like 13 or 14.) How can I ensure that when ...

Confusing type conversion - 2 Bytes to Double

I was recently asked to take over a project in which waveform data is sampled from a power converter and sent to an intelligent agent where calculations are done and the appropriate actions are taken based on the results. The following (java)snippet is what the previous coder used to convert the byte array into an array of doubles: ...

jQuery input validation for double/float

Hi What's the best method to mask an input field to only allow float/double, without any jquery plugin. Acutally i'm doing it like this: $("#defaultvalue").bind("keypress", function(e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { return false; } ...

Double & Float method parameters execution when called in C#

Hi there. Here's a small snippet of code, when called it outputs 'double'. Why? What's the reasoning behind this. Why doesn't it print 'float'? class source { static void Main() { Receiver r = new Receiver(); r.Method1(1.1); } } class Receiver { public virtual void Method1(double f) { Debug.Print("d...

Android GPS Result Format

I have noticed with testing GPS locations, a value such as -123 might come up on Android as -123.83333336... is there anyway to format incoming GPS locations, such as within 2 decimal points? This way I can store values like -123.83 opposed to longer numeric values. I have checked out DecimalFormat and NumberFormat, these are strings and...

How can I print a C double bit-by-bit to see the low-level representation?

I want to learn how the computer represents the double type in bit, but the & and | bit operators can't use double. And memcpy(&d, &src, 8) also doesn't seem to work. Any suggestions? ...

Saving Double.MinValue in SQLServer

Using a TSQL update command against a SQLServer database, how can I update a column of type FLOAT with the smallest possible double value? The smallest possible double value in hex notation being 3ff0 0000 0000 0001 (http://en.wikipedia.org/wiki/Double%5Fprecision) ...

Proper notation using doubles

It is more stylistically acceptable in java to write constants in double operations with or without ".0" ? As in, double var= 200.0; double d= var/250.0; double h= 1.0 - d; vs. double var= 200; double d= var/250; double h= 1 - d; Thanks ...

Conversion of a decimal to double number in C# results in a difference

Summary of the problem: For some decimal values, when we convert the type from decimal to double, a small fraction is added to the result. What makes it worse, is that there can be two "equal" decimal values that result in different double values when converted. Code sample: decimal dcm = 8224055000.0000000000m; // dcm = 8224055000 ...

[C#] Convert string to double with 2 digit after decimal separator

All began with these simple lines of code: string s = "16.9"; double d = Convert.ToDouble(s); d*=100; The result should be 1690.0, but it's not. d is equal to 1689.9999999999998. All I want to do is to round a double to value with 2 digit after decimal separator. Here is my function. private double RoundFloat(double Value) { floa...