Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

void wxPropertyGrid::DoubleToString ( wxString &  target,
double  value,
int  precision,
bool  removeZeroes,
wxString *  precTemplate 
) [static]

Standardized double-to-string conversion.

Definition at line 400 of file props.cpp.

{
    if ( precision >= 0 )
    {
        wxString text1;
        if (!precTemplate)
            precTemplate = &text1;

        if ( !precTemplate->length() )
        {
            *precTemplate = wxT("%.");
            *precTemplate << wxString::Format( wxT("%i"), precision );
            *precTemplate << wxT('f');
        }

        target.Printf( precTemplate->c_str(), value );
    }
    else
    {
        target.Printf( wxT("%f"), value );
    }

    if ( removeZeroes && precision != 0 && target.length() )
    {
        // Remove excess zeroes (do not remove this code just yet,
        // since sprintf can't do the same consistently across platforms).
        wxString::const_iterator i = target.end() - 1;
        size_t new_len = target.length() - 1;

        for ( ; i != target.begin(); i-- )
        {
            if ( wxPGGetIterChar(target, i) != wxT('0') )
                break;
            new_len--;
        }

        wxChar cur_char = wxPGGetIterChar(target, i);
        if ( cur_char != wxT('.') && cur_char != wxT(',') )
            new_len++;

        if ( new_len != target.length() )
            target.resize(new_len);

        /*
        unsigned int cur_pos = target.length() - 1;
        wxChar a;
        a = target.GetChar( cur_pos );
        while ( a == wxT('0') && cur_pos > 0 )
        {
            cur_pos--;
            a = target.GetChar( cur_pos );
        }

        wxChar cur_char = target.GetChar( cur_pos );
        if ( cur_char != wxT('.') && cur_char != wxT(',') )
            cur_pos += 1;

        if ( cur_pos < target.length() )
            target.Truncate( cur_pos );
        */
    }
}

Generated by  Doxygen 1.6.0   Back to index