Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Trailing zeroes in CExtGridCellCurrency Collapse All
Subject Author Date
Ashley Gullen Jan 6, 2007 - 7:44 AM

I’m using a CExtGridCellCurrency to display percentages. I set it up like so:

pCurrency->SetNumDigits(6);
pCurrency->SetCurrencySymbol("%");
pCurrency->SetPositiveOrder(1);
pCurrency->SetNegativeOrder(5);

This means a value of 50.5 shows up as "50.500000%", and 100 shows up "100.000000%".
Is there any way to remove the trailing zeroes? I would like 50.5 to show up as "50.5%", and 100 to show up as "100%".

Technical Support Jan 7, 2007 - 10:02 AM

We have just added the SetAllowTrailingZeroes() and GetAllowTrailingZeroes() methods to the CExtGridCellNumber and CExtGridCellCurrency classes, with which you can allow or suppress the trailing zeroes. Until the next version you can temporarily change the CExtGridCellCurrency::TextGet() method in this way:

void CExtGridCellCurrency::TextGet( CExtSafeString & strCopy ) const
{
    ASSERT_VALID( this );
    if(        (GetStyleEx()&__EGCS_EX_UNDEFINED_ROLE) != 0 
        ||    IsEmpty()
        )
    {
        strCopy = _T("");
        return;
    }
    strCopy.Empty();

VARIANT varCopy;
    ::VariantInit( &varCopy );
HRESULT hr = 
        ::VariantCopy( 
            &varCopy, 
            LPVARIANT( LPCVARIANT( this ) )
            );
    if(        FAILED(hr)
        ||    (!OnTextGetPrepareVariant( &varCopy ))
        )
    {
        ASSERT( FALSE );
        return;
    }

CExtSafeString sNumberText;
bool bRet = OnQueryNumberText( &varCopy, sNumberText );
    
    ::VariantClear( &varCopy );
    
    if( !bRet )
        return;

UINT nNumDigits = OnQueryNumDigits();
//    if( ! OnQueryTrailingZeroes() )
    {
        INT nPosPoint = sNumberText.ReverseFind( _T(’.’) );
        UINT nNumDigitsReal = 0;
        if( nPosPoint >= 0 )
            nNumDigitsReal = min( sNumberText.GetLength() - 1 - nPosPoint, 9 );
        if( nNumDigitsReal < nNumDigits )
            nNumDigits = nNumDigitsReal;
    }

CURRENCYFMT fmt;
    memset( &fmt, 0, sizeof(CURRENCYFMT) );

    fmt.NumDigits = nNumDigits;
    fmt.LeadingZero = OnQueryLeadingZero();
    fmt.NegativeOrder = OnQueryNegativeOrder();
    fmt.PositiveOrder = OnQueryPositiveOrder();

CExtSafeString sGrouping;
    OnQueryGrouping( sGrouping );
    sGrouping.Remove( _T(’;’) );
    sGrouping.TrimRight( _T(’0’) );
    fmt.Grouping = _ttoi( sGrouping );
    
CExtSafeString sDecimalSep;
    OnQueryDecimalSeparator( sDecimalSep );
    fmt.lpDecimalSep = sDecimalSep.GetBuffer( sDecimalSep.GetLength() );
    sDecimalSep.ReleaseBuffer();
    
CExtSafeString sThousandSep;
    OnQueryThousandSeparator( sThousandSep );
    fmt.lpThousandSep = sThousandSep.GetBuffer( sThousandSep.GetLength() );
    sThousandSep.ReleaseBuffer();
    
CExtSafeString sCurrencySymbol;
    OnQueryCurrencySymbol( sCurrencySymbol );
    fmt.lpCurrencySymbol = sCurrencySymbol.GetBuffer( sCurrencySymbol.GetLength() );
    sCurrencySymbol.ReleaseBuffer();

    VERIFY(
        g_ResourceManager->GetCurrencyFormat(
              0,
              sNumberText,
              &fmt,
              strCopy.GetBuffer( 100 ),
              100
            ) != 0
        );
    strCopy.ReleaseBuffer();
}