how to calculate Auto screenscalefactor ratio

my resources are 960 *640 and view~~>create; i created like that in my CCEGLView~~ android scalefactor ratio is

m_sSizeInPoint.width = width;
m_sSizeInPoint.height = height;

// calculate the factor and the rect of viewport
m_fScreenScaleFactor = MAX ((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
(float)m_sSizeInPixel.height / m_sSizeInPoint.height);
int viewPortW = (int)(m_sSizeInPoint.width * m_fScreenScaleFactor);
CCLOG (“width and height ________________________________________________is %f,%f”,m_sSizeInPoint.width,m_sSizeInPixel.height)

int viewPortH = (int)(m_sSizeInPoint.height * m_fScreenScaleFactor);
m_rcViewPort.origin.x = (m_sSizeInPixel.width - viewPortW) / 2;
m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2;
m_rcViewPort.size.width = viewPortW;
m_rcViewPort.size.height = viewPortH;

so problem is my sprite height is little bit exceeded 40 pixels up/down so how to calculate scale factor for all android devices

thank you