|
The second syntax is invalid: the base class (A) needs to be constructed before your child class (B). So the only way to do that is to put it in the constructor initialisation list.
|
|
|
|
|
|
the value 0.00922307 should be rounded to 0.01.
Is there any method available in c++?
|
|
|
|
|
Math.round ();
public static long round( double a )
Parameters
a
a double value.
Returns
the value of the argument rounded to the nearest long value.
Description
Returns the closest long to the argument.
If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE.
If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I need to get result with two decimal places not long value.
|
|
|
|
|
ROUND(nExpression, nDecimalPlaces)
Returns
Numeric
Arguments
nExpression
Specifies the numeric expression whose value is to be rounded.
nDecimalPlaces
Specifies the number of decimal places nExpression is rounded to.
If nDecimalPlaces is negative, ROUND( ) returns a whole number containing zeros equal in number to nDecimalPlaces to the left of the decimal point. For example, if nDecimalPlaces is –2, the first and second digits to the left of the decimal point in the value are 0.
This may work check once...
Megha
|
|
|
|
|
Which language is that ?
When you copy paste documentation that you found, it would be better to post the link instead.
|
|
|
|
|
AFAIK, this is java libraries, not C++.
|
|
|
|
|
That looks like C#, not C++!
Steve
|
|
|
|
|
I have taken this text from the VS 6.0 help, but without seeing from which library. It is java. Sorry for the confusion.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
In general, rounding is needed when you want to display the number as a string. Is that the case for you ?
If yes, you can use sprintf and specify a precision:
char szBuff[25];<br />
sprintf(szBuff,"%.2f",yourDouble);
This tells sprintf to print 2 decimals after the floating point.
If you need to use it as a double (and not a string), you can multiply it by 100, convert it to an int and divided it back by 100.0:
double yourDouble = 0.00922307;<br />
int yourInt = yourDouble * 100;<br />
double roundedDouble = yourInt / 100.0;
(you must be carefull and divide by 100.0, not by 100, otherwise the you will end up with an integer and not a double).
|
|
|
|
|
but as per logic it returns 0.00 not 0.01 which required.
|
|
|
|
|
Cedric Moonen wrote: double yourDouble = 0.00922307;
int yourInt = yourDouble * 100;
double roundedDouble = yourInt / 100.0;
I think
double yourDouble = 0.00922307 + .005;
will be more right.
- NS -
|
|
|
|
|
Yes, you are perfectly right
I forgot that the rounding is always rounded-down.
|
|
|
|
|
This is another way to do that.
I did it with VC++ 6.0 to be used in my project. The return value is a string to be shown in the GUI, but you can easily adapt it just for numbers.
CString CMyDoc::CutAndRoundStringToNDecimals (double dValue, const int nDec)
{ double dTemp = 0, dFract = 0, dInt = 0, dRes = 0;
int nCount = 0;
CString cLetter = "";
dTemp = dValue*pow(10,nDec);
dFract = modf (dTemp, &dInt);
if (dFract >= 0.5)
dInt++;
dRes = dInt/pow(10,nDec);
CString szResult;
szResult.Format ("%s%f", szResult, dRes);
int nLarge = szResult.GetLength ();
for (int i = 0; i < nLarge; i++)
{ nCount++;
CString cLetter = szResult.GetAt (i);
if (cLetter == ".")
{ nCount += nDec;
break;
}
}
LPTSTR pStr = szResult.GetBufferSetLength (nCount);
szResult.ReleaseBuffer ();
return szResult;
}
Hope it helps
I forgot to say that math.h has to be included to use pow () and modf()
-- modified at 11:41 Wednesday 26th September, 2007
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hello,
i have come across with the int version of this function somewhere and changed to double in order to avoid precision problems for big and small values. You may use the int version if it fits your requirement.
double roundExt(double Num, double Seed)
{
// get rational factor
double fac = Num / Seed;
// get natural factor
fac = (fac < 0) ? (ceil(fac - 0.5)) : (floor(fac + 0.5));
// fac = (fac < 0) ? static_cast<int>(fac-0.5) : static_cast<int>(fac+0.5);
// return multiple
return fac * Seed;
}
roundExt(0.009,0.01); is the usage.
Hope this helps.
Bekir.
|
|
|
|
|
Yes , it working fine.
Thanks to all.
|
|
|
|
|
dear friends,
if i open link of rediffmail.com can i post my user ID (which i'll hard code in my VC++ application) directly on rediffmail window in User Id edit box??
is it possible? if yes can anybody help me out to do the same??
Megha
|
|
|
|
|
Do you want to fill out some elements on the a page?
|
|
|
|
|
yes for example Username on tht particular page
|
|
|
|
|
Naveen.R's answer exactly answer to your question.
|
|
|
|
|
|
Dear all,
I need msgrua.h and msgruaid.h files for my MSN Messanger plugins.
so can any body help me out for this.
please let me know how to download these files.
Thank you
Rahul Vaishnav
|
|
|
|
|
have you ever googled a bit ?
the first link i found when searching for msgrua.h is this[^]...
|
|
|
|
|
Thank you very much toxcct...
|
|
|
|