Thursday, February 3, 2011

convert double to string (non-cstring)?

Convert double to string (non-cstring)?


char str[10];
double num = 1.42463;
sprintf(str, "%.2f", num);

Example:
double dValidatedPercentageValue = 0;

dValidatedPercentageValue = RoundADouble(dValue);
char str[10];
sprintf(str, "%.2f", dValidatedPercentageValue);
pGrid->PutTextMatrix(Row, Col, _bstr_t(str));


Example:
Function to round of for 2 Decimal Precision:

double Matrix::RoundADouble(double x)

{
double f, xi, xf;
xf = modf(x,&xi);
f = floor(xf*100+0.5)/100.0;
return xi + f;
}

No comments:

Post a Comment

Health Benefits of Cashews

  Benefits of Cashews. Healthy food is an integral part of healthy body. Regular exercises such as Yoga and healthy diet is important to...