double

sstream not working...(STILL)

I am trying to get a double to be a string through stringstream, but it is not working. std::string MatlabPlotter::getTimeVector( unsigned int xvector_size, double ts ){ std::string tv; ostringstream ss; ss << "0:" << ts << ":" << xvector_size; std::cout << ss.str() << std::endl; return ss.str(); } It outputs only...

Convert a string with a hex representation of an IEEE-754 double into JavaScript numeric variable

Suppose I have a hex number "4072508200000000" and I want the floating point number that it represents (293.03173828125000) in IEEE-754 double format to be put into a JavaScript variable. I can think of a way that uses some masking and a call to pow(), but is there a simpler solution? A client-side solution is needed. This may help. I...

sIFR double titles?

I used the latest sIFR version, and for some reason it shows the title double. I've experienced this problem on 2 pages now. I uploaded an example here: http://www.romenov.com/fairflex/form.html and for some reason, the problem does not occur on page.html Any clues? ...

Java Double to String conversion without formatting

I have the number 654987. Its an ID in a database. I want to convert it to a string. The regular Double.ToString(value) makes it into scientific form, 6.54987E5. Something I dont want. Other formatting functions Ive found checks the current locale and adds appropriate thousand separators and such. Since its an ID, I cant accept any for...

how to CAST a double to int in C

I've got a double... say double d = 25.342; How can I get the 25 value? ( If it were -12.46 I'd like to get -13) Thanks! Manuel ...

What's the quickest/best way to format a ?double to currency for string output in C#?

When using .ToString("{blah}") it gives an error because it's a ?double not a double... 'bad parameter' etc Note this does not seem to be working, sometimes I get '5.7': double itemListPrice = Math.Round((double)((item.UserIntervalPrice * item.Volume) - ((item.UserIntervalPrice * item.Volume) * (item.VolumeDiscount / 100))),2); h...

C#: What's the best way to compare Double and Int?

Hello everybody, The following code in C# doesn't work: int iValue = 0; double dValue = 0.0; bool isEqual = iValue.Equals(dValue); So, the question: what's the best way to compare Double and Int? -- Best Regards, Murat ...

What is the inclusive range of float and double in Java?

What is the inclusive range of float and double in Java? Why are you not recommended to use float or double for anything where precision is critical? ...

How deal with the fact that most decimal fractions cannot be accurately represented in binary?

So, we know that fractions such as 0.1, cannot be accurately represented in binary base, which cause precise problems (such as mentioned here: http://stackoverflow.com/questions/1421520/formatting-doubles-for-output-in-c). And we know we have the decimal type for a decimal representation of numbers... but the problem is, a lot of Math m...

Why does Visual Studio 2008 tell me .9 - .8999999999999995 = 0.00000000000000055511151231257827?

When I type this into the Visual Studio 2008 immediate window: ? .9 - .8999999999999995 It gives me this as the answer: 0.00000000000000055511151231257827 The documentation says that a double has 15-16 digits of precision, but it's giving me a result with 32 digits of precision. Where is all that extra precision coming from? ...

What is the minimum buffer size for sprintf with %g?

The problem is to statically allocate a buffer large enough to fit a printed double, formatted with %g at maximum precision. This seems like a simple enough task, bu I'm having trouble. The best I have come up with (assuming the number to be printed is x) is char buf[1 + DBL_DIG + DBL_DIG + 1 + 1 + 1 + DBL_DIG + 1]; int len = sprintf(...

Why is System.Math and for example MathNet.Numerics based on double?

All the methods in System.Math takes double as parameters and returns parameters. The constants are also of type double. I checked out MathNet.Numerics, and the same seems to be the case there. Why is this? Especially for constants. Isn't decimal supposed to be more exact? Wouldn't that often be kind of useful when doing calculations? ...

Unexpected results using istringstream for string to double conversion in C++

I'm currently trying to take a string ("0.1") and convert it to a double using C++ in Xcode on 10.6 with gcc4.2. I'm using a function I pinched from another question, but when I try to use the function, my input according to gdb is (string)"0.1", but my output is (double)2.1220023981051542e-314. Here is my snippet copied straight out t...

How to properly display a price up to two decimals (cents) including trailing zeros in Java?

There is a good question on rounding decimals in Java here. But I was wondering how can I include the trailing zeros to display prices in my program like: $1.50, $1.00 The simple solution of String.format("%.2g%n", 0.912385); works just fine, but omits the trailing zero if it is at the last decimal place. The issue comes up in my pro...

What is faster on division? doubles / floats / UInt32 / UInt64 ? in C++/C

Hi everyone, I did some speed testing to figure out what is the fastest, when doing multiplication or division on numbers. I had to really work hard to defeat the optimiser. I got nonsensical results such as a massive loop operating in 2 microseconds, or that multiplication was the same speed as division (if only that were true). After...

integer automatically converting to double but not float

Hi all, I have a function like below: void add(int&,float&,float&); and when I call: add(1,30,30) it does not compile. add(1,30.0,30.0) also does not compile. It seems that in both cases, it gets implicitly converted to double instead of float. So, do you suggest that it is better to re-define add as add(int&,double&,double&)? Is...

Why do MSTests Assert.AreEqual(1.0, double.NaN, 0.0) pass?

Short question, why do Assert.AreEqual(1.0, double.NaN, 0.0) pass when Assert.AreEqual(1.0, double.NaN) do not? Is it an error in MSTest or am I missing something here? Best regards, Egil. Update: Should probably add, that the reason behind my question is, that I have a bunch of unit tests that unfortunately passed due to the result o...

Can doubles be used to represent a 64 bit number without loss of precision

I want to use lua (that internally uses only doubles) to represent a integer that can't have rounding errors between 0 and 2^64-1 or terrible things will happen. Is it possible to do so? ...

how do I round numbers with NSNumberFormatter

I've got a calculation for example 57 / 30 so the solution will be 1,766666667.. How do i first of all get the 1,766666667 i only get 1 or 1.00 and then how do i round the solution (to be 2)? thanks a lot! ...

How to save double to file in python?

Let's say I need to save a matrix(each line corresponds one row) that could be loaded from fortran later. What method should I prefer? Is converting everything to string is the only one approach? ...