double

Adding floats does not yield a correct result

谁说胖子不能爱 提交于 2019-12-12 04:26:00
问题 Imagine the following situation. Amounts are added to a total in a loop: float total = 0; float[] amounts = new float[]{...}; foreach(float amount in amounts) { total += amount; } total , as wel as all the amount s are written to a database. When I calculate SUM(amount) in SQL, it results in a value that differs from total . Moreover, when I do the same calculation in C#, but this time adding the amounts to a value of type double, double total = 0; //the rest of the code is the same as above

Double scientific notation format 10th power C#

…衆ロ難τιáo~ 提交于 2019-12-12 03:42:48
问题 I am having double value = 30308950000; I want to display it like 3.03x10^10 How can I achieve it using C#? I have tried double value = 30308950000; Console.WriteLine(value.ToString("0.###E+0", CultureInfo.InvariantCulture)); output = 3.03E+10 I dont want the 3.03E+10 format but 3.03x10^10 . Thanks 回答1: Easy fix: double value = 30308950000; Console.WriteLine( value.ToString("0.###E+0", CultureInfo.InvariantCulture) .Replace("E-","x10^-") .Replace("E+","x10^")); Shout out to Jon Skeet! :) 回答2:

Convert double to int (java)

怎甘沉沦 提交于 2019-12-12 03:32:28
问题 I'm trying to make a program to simulate the solar system. for(int i=0;i<1000;i++) { double X=(160*Math.cos((2*PI*i)/365)); double Y=(160*Math.sin((2*PI*i)/365)); posX=Math.round(X); posY=Math.round(Y); cadre.repaint(); sleep(200); } f.setVisible(false); To make my planets turning around the sun, I have a formula; the problem is that i have a double number with this formula, and i can't make him become an int (i tried floor(X), Math.round(X), doesn't work (error : incompatible types :

Number changes when converting Double to Numerics.BigInteger

时光怂恿深爱的人放手 提交于 2019-12-12 03:22:46
问题 using System.Numerics; double doubleNumber = Math.Pow(1000, 99); // = 1.0E+297 BigInteger bigBase = (BigInteger)bigNumber; // = 1000000000000000017652801462756379714374878780719864776839443139119744823869255243069012222883470359078822072829219411228534934402712624705615450492327979456500795456339201761949451160807447294527656222743617592048849967890105831362861792425329827928397252374398383022243308510390698430058459037696 Why is the BigInteger value not just 1 kagillion (1,000 followed by a

Understanding the datatype Double

这一生的挚爱 提交于 2019-12-12 03:18:34
问题 I am trying to write a program in C to get the percent of even numbers in an array. I am thinking of writing it using int datatype. But some one mentioned to me using double will be easier. I don't understand that. Can anyone guide me with it? What does double datatype return? Can the return statement be given as return (double)? What will that give? Can double convert a real number to a percent? Eg: 0.5 to 50.0 回答1: The int datatype is, as the name would suggest, integers (or whole numbers).

How to handle word with apostrophe?

a 夏天 提交于 2019-12-12 02:26:37
问题 I'm filling an arraylist with some cities, but one of them ("Reggio nell'Emilia") have an apostrophe in its name and when i select it in the app it crashes. Here is the code: SQLiteDatabase db_read = db.getReadableDatabase(); city = new ArrayList<Object>(); Cursor result; for (int i =0 ; i<region.size(); i++) { result = db_read.rawQuery("select distinct city from merchants where region='"+region.get(i)+"' order by city ASC",null); ArrayList<String> cities = new ArrayList<String>(); while

integer division vs regular division

坚强是说给别人听的谎言 提交于 2019-12-12 02:18:26
问题 I need to compare an integer in a loop to the quotient of a long and a long . in order to not do integer division, if I understand correctly do I need to convert one of the longs into a double? long prime = primes[d]; int i = 1; // "inputNumber / prime" should not be integer division, while it is now. // How do I do this yet still compare it to an "int" afterwards? while (i < (inputNumber / prime)) { primes[i*prime] = 0; i++; } That's the code snippet. primes is an array filled with long s.

Remove values in vector from double variable in R

会有一股神秘感。 提交于 2019-12-12 01:42:50
问题 I have a variable of type double X: 1.5 1.3 0.6 1.8 2.9 2.1 1.5 1.4 5.8 0.0 and a vector V: c(0.6,2.9) . I want to remove the values in V from X test<-X[!X %in% V] The values are not removed from test: test [1] 1.5 1.3 0.6 1.8 2.9 2.1 1.5 1.4 5.8 0.0` I tried the following: are.equal <- function(x, y, eps = .Machine$double.eps^0.5) abs(x - y) < eps test=X[!(are.equal(X,0.6))] 0.6 were removed.. I could have something odd in my data or my system. Any idea? 来源: https://stackoverflow.com

Separate a double into it's sign, exponent and mantissa

£可爱£侵袭症+ 提交于 2019-12-12 01:12:17
问题 I've read a few topics that do already broken down doubles and "puts it together" but I am trying to break it into it's base components. So far I have the bit nailed down: breakDouble( double d ){ long L = *(long*) &d; sign; long mask = 0x8000000000000000L; if( (L & mask) == mask ){ sign = 1; } else { fps.sign = 0; } ... } But I'm pretty stumped as to how to get the exponent and the mantissa. I got away with forcing the double into a long because only the leading bit mattered so truncation

how to convert long double to string format in Xcode ? or how to solve error “use of undeclared identifier 'to_string' ”

与世无争的帅哥 提交于 2019-12-12 01:09:57
问题 this code works in microsoft visual c++, but when i run this in Xcode, it give me error No member named 'to_string' in namespace 'std' double learningRates[] = {0.00015, 0.00065, 0.00075, 0.0015, 0.0045, 0.0065, 0.0075, 0.055}; long double learning_Value = learningRates[learningRate_Index]; string pathtotal_weight_Bias= pathWeightBias +"/" + "best_weight_Bias" + convertInt(MaxEpochs) +"_LR"+ to_string(learning_Value)+".xml"; even if i used std::to_string(learning_Value), even than it gives