double

C++ converting Variant Decimal to Double Value

試著忘記壹切 提交于 2019-12-11 09:58:52
问题 I have a _variant_t variable that contains a DECIMAL value from a database.. The problem is, I get an undefined value when I try to directly convert it to double type. For example, I have a decimal value = 1000.111 _varaint_t MyVar = getValueFromDatabase(); // MyVar is a decimal value = 1000.111 double MyDouble = (double) MyVar.dblVal; cout << MyDouble << endl; // Prints "4.941204871279e-318#DEN" What is the right way to convert Decimal to Double in C++? UPDATE: When I try this, _varaint_t

??? Error using ==> plus Integers can only be combined with integers of the same class, or scalar doubles

六眼飞鱼酱① 提交于 2019-12-11 09:54:44
问题 When i'm trying to add pixel data to data created by gaussian randn() function it's spitting the error ??? Error using ==> plus Integers can only be combined with integers of the same class, or scalar doubles. This is my code: im = imread( 'ngc6543a.jpg' ); % matlab example image x = randn( size (im) ); % create gaussian distributed values t = im + x; % add them together, this throws the error 回答1: Convert the integers (uint8) from your read image im to double: t = double(im) + x; 来源: https:/

Java regex split double from string

ε祈祈猫儿з 提交于 2019-12-11 09:52:27
问题 I am having a problem splitting something like the following string: 43.80USD What I want is to be able to split the expression into an array that has "43.80" as the first element and "USD" as the second. So the result would be something like: ["43.80", "USD"] I am sure there is some way to do this with regex, but I am not proficient enough with it to figure it out on my own. Any help would be much appreciated. 回答1: If the format of your string is fixed you can split it as follows String[]

C++ converting string to double using atof

两盒软妹~` 提交于 2019-12-11 09:52:26
问题 I cannot get the atof() function to work. I only want the user to input values (in the form of decimal numbers) until they enter '|' and it to then break out the loop. I want the values to initially be read in as strings and then converted to doubles because I found in the past when I used this method of input, if you input the number '124' it breaks out of the loop because '124' is the code for the '|' char. I looked around and found out about the atof() function which apparently converts

Losing precision when multiplying Doubles in C

末鹿安然 提交于 2019-12-11 09:33:29
问题 I am trying to get multiplay decimal part of a double number about 500 times. This number starts to lose precision as time goes on. Is there any trick to be able to make the continued multiplication accurate? double x = 0.3; double binary = 2.0; for (i=0; i<500; i++){ x = x * binary; printf("x equals to : %f",x); if(x>=1.0) x = x - 1; } Ok after i read some of the things u posted i am thinking how could i remove this unwanted stuff from my number to keep multiplication stable. For instance in

Can I raise a Java BigInteger to a double/float power?

折月煮酒 提交于 2019-12-11 08:48:47
问题 I'm a .NET developer, but apparently no library exists to do this in .NET. So, is there any BigInteger implementation in Java that allows raising a BigInteger to a double exponent: BigInteger result = BigInteger.pow( base, dblExponent); // Base is a BigInteger, dblExponent is a double. 回答1: try this: BigInteger base = new BigInteger("10"); double base1 = base.doubleValue(); double dblExponent = 10; double res = pow(base1, dblExponent); BigDecimal result = new BigDecimal(res); but pay

Is Math.Abs(x) < double.Epsilon equivalent to Math.Abs(x) == 0d?

蓝咒 提交于 2019-12-11 08:35:12
问题 After a bit of light reading, this article piqued my interest: I'd have thought that yes, the two statements are equivalent, given MSDN's statement: Represents the smallest positive Double value that is greater than zero. This field is constant. Curious to see what people think. EDIT: Found a computer with VS on and ran this Test. Turns out that yes, as expected, they're equivalent. [Test] public void EpsilonTest() { Compare(0d); Compare(double.Epsilon); Compare(double.Epsilon * 0.5); Compare

Print float or double in non scientific notaion

走远了吗. 提交于 2019-12-11 08:28:42
问题 Float or double always gives answer in scientific notation if number of digits are 7 or more. Like an decimal number 10000000.5 it is giving 1e-08 something. I am wondering if we can print 10000000.5 without adding any new header file. 回答1: If you are printing to cout , use std::cout.setf( std::ios::fixed, std::ios::floatfield ); See it work. You might also want std::cout.precision(1) to set the number of digits after the decimal point. 回答2: printf("%.1f", someFloat) should do that for you,

Parsing decimal numbers, some of which lack a decimal separator, in JSON data using JSON-Simple (Java)

会有一股神秘感。 提交于 2019-12-11 08:17:06
问题 I am trying to use the JSON-Simple JSON processor library. When parsing JSON fragment such as: "speed":1.13 …I call get and cast as a Double . No problem. Double speed = ( Double ) wind.get( "speed" ); But then I encounter a value without a decimal fraction. Ex: 1 rather than 1.0 . "speed":1 Granted, the publisher of this data should have written "speed":1.0 . But they did not. My get with casting throws an exception: Exception in thread "main" java.lang.ClassCastException: class java.lang

while loop parsing Double.IsNaN improperly

有些话、适合烂在心里 提交于 2019-12-11 08:00:58
问题 Language: Java, IDE: eclipse mars The program is supposed to prompt the user (using JOptionPane) for a positive value. I'm trying to catch the invalid entries. My while statement catches the negative numbers but not the strings. When a negative number is entered, the prompt is shown again, but when a string value is entered, the exception is caught and the program moves on (when it should re prompt the user). Once a positive value has been entered, the program assigns it to a value in another