format the percentDP score in PaneDisplay using the same code in PercentageDisplay

This commit is contained in:
Chris Danford
2005-04-05 09:29:05 +00:00
parent 9643e9986a
commit 62a2834202
3 changed files with 20 additions and 12 deletions
+16 -11
View File
@@ -121,17 +121,7 @@ void PercentageDisplay::Refresh()
}
else
{
// TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent
// score that's too high and doesn't match up with the calculated grade.
float fTruncInterval = powf(0.1f, (float) PERCENT_TOTAL_SIZE-1);
// TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to
// fPercentDancePoints to correct for this.
fPercentDancePoints += 0.000001f;
fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval );
sNumToDisplay = ssprintf( "%*.*f%%", (int) PERCENT_TOTAL_SIZE, (int) PERCENT_DECIMAL_PLACES, fPercentDancePoints*100 );
sNumToDisplay = FormatPercentScore( fPercentDancePoints, PERCENT_TOTAL_SIZE, PERCENT_DECIMAL_PLACES );
// HACK: Use the last frame in the numbers texture as '-'
sNumToDisplay.Replace('-','x');
@@ -141,6 +131,21 @@ void PercentageDisplay::Refresh()
m_textPercent.SetText( sNumToDisplay );
}
CString PercentageDisplay::FormatPercentScore( float fPercentDancePoints, int iTotalSize, int iDecimalPlaces )
{
// TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent
// score that's too high and doesn't match up with the calculated grade.
float fTruncInterval = powf( 0.1f, (float)iTotalSize-1 );
// TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to
// fPercentDancePoints to correct for this.
fPercentDancePoints += 0.000001f;
fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval );
return ssprintf( "%*.*f%%", iTotalSize, iDecimalPlaces, fPercentDancePoints*100 );
}
/*
* (c) 2001-2003 Chris Danford
* All rights reserved.