#### Category : double

I get a negative output to a positive double variable. My object is: Fahrzeug fr("BMW",200.45); class Fahrzeug { private: string p_sName; double p_dMaxGeschwindigkeit; public: Fahrzeug(string p_sName, double p_dMaxgeschwindigkeit) { this->p_sName = p_sName; this->p_dMaxGeschwindigkeit = p_dMaxGeschwindigkeit; //the output is negative cout << "Der Name des Fahrzeugs: " << this->p_sName << "n" << "Die maximale Geschwindigkeit des ..

I use mpdecimal library libmpdec++(https://www.bytereef.org/mpdecimal/index.html). I found ways to convert decimals to int and string. But I didnt find way to convert decimal to double. Is there any ways? (Except convert to string and following conversion to double). Source: Windows Que..

#include<iostream> #include<cmath> using namespace std; float san= 0.25 ; float var= 0.75; int findFact(int n)//factorial { return n == 1 ? 1 : n * findFact(n – 1); } int findNcR(int n, int r)//combination nCr { return findFact(n) / (findFact(n – r) * findFact(r)); } double prob(int s, int v){ //recursive function for probability if(s==5) ..

I am running a simulation in C++ where I need to calculate values under a loop which runs from 0 to 10 seconds but each increment is of 10ms i.e. for(i=0;i<=10;i+=0.01). The statement under this loop calculate the values for a variable , say "velocity at time time ‘t’ = vt’ where ‘t’ is equal ..

double floaty=36.6736872; cout<<fixed<<setprecision(10)<<floaty; My output is "36.6736872000"; I want my zeros to be some other number. Eg: If I want zeros to be ^. then the output should be 36.6736872^^^ I don’t have any idea other than using setw and setfill to get my desired output in single line of code Source: Windows Que..

well thanks for clicking in. i want to calculate 10(yes only 10) to the power n[0..308] fast. i came up with some methods. 1) double f(int n) { return pow(10.0, n); } double f1(int n) { double a = 10.0; double res = 1.0; while(n) { if(n&1) res *= a; a *= a; n >>= ..

On the learncpp.com there is advice to write doubles as: double num {5.0} Is there any real difference between that and: double num {5} It seems that my compiler (VS 2019) treats those as equivalent. Source: Windows Que..