티스토리 뷰


차트의 Min 과 Max를 적절히 조절하기 위한 함수

만든이 - 민승기

void CKoreaMarket::calcGridStep( double *pdMin, double *pdMax, int num )
{
double step = (*pdMax - *pdMin ) / num;
step = (*pdMax - *pdMin) / (num - 1) ;

if( step < 0 )
{
*pdMax = *pdMin = 0; step = 0;
}
if( step == 0 ) step = 1.0;
else if( step < 0.001 ) step = ((int)(step * 10000) + 1) / 10000.0;
else if( step < 0.01 ) step = ((int)(step * 1000) + 1) / 1000.0;
else if( step < 0.1 ) step = ((int)(step * 100) + 1) / 100.0;
else if( step < 1 ) step = ((int)(step * 10) + 1) / 10.0;
else if( step < 10 ) step = (int)(step + 1);
else if( step < 100 ) step = ((int)(step / 10) + 1) * 10;
else if( step < 1000 ) step = ((int)(step / 100) + 1) * 100;
else if( step < 10000 ) step = ((int)(step / 1000) + 1) * 1000;
else if( step < 100000 ) step = ((int)(step / 10000) + 1) * 10000;
else if( step < 1000000 ) step = ((int)(step / 100000) + 1) * 100000;
else if( step < 10000000 ) step = ((int)(step / 1000000) + 1) * 1000000;

if( *pdMin >= 0 ) {
if((int)(*pdMin/step) * step == *pdMin){
*pdMin = (int)(*pdMin/step - 0.5) * step; // adjust min
}
else{
*pdMin = (int)(*pdMin/step)*step;
}
} else {
if((int)(*pdMin/step - 1) * step == *pdMin)
*pdMin = (int)(*pdMin/step - 1.5) * step; // adjust min
else
*pdMin = (int)(*pdMin/step - 1) * step;
}

*pdMax = *pdMin + step * num; // adjust min & max
// return step;
}

댓글