Use dedicated function to get rounded value of wxFloatProperty

wxFloatProperty::ValueToString() returns string representing value rounded with required precision so we don't need to retrieve wxPG_FLOAT_PRECISION attribute and do rounding on our own.
This commit is contained in:
Artur Wieczorek 2019-04-20 22:38:58 +02:00
parent 2898e8136a
commit 76584e2d3c
2 changed files with 8 additions and 19 deletions

View File

@ -381,14 +381,8 @@ bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* proper
// Min/Max check
wxFloatProperty::DoValidation(property, v_d, NULL, mode);
int precision = -1;
wxVariant v = property->GetAttribute(wxPG_FLOAT_PRECISION);
if ( !v.IsNull() )
{
precision = v.GetInteger();
}
s = wxNumberFormatter::ToString(v_d, precision, wxNumberFormatter::Style_NoTrailingZeroes);
wxVariant v(v_d);
s = property->ValueToString(v, 0);
}
else
{

View File

@ -465,24 +465,19 @@ bool NumericValidation( const wxPGProperty* property,
if ( minOk || maxOk )
{
// Get required precision.
int precision = -1;
variant = property->GetAttribute(wxPG_FLOAT_PRECISION);
if ( !variant.IsNull() )
{
precision = variant.GetInteger();
}
// Round current value to the required precision.
wxString strVal = wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None);
variant = value;
wxString strVal = property->ValueToString(variant, wxPG_FULL_VALUE);
strVal.ToDouble(&value);
// Round minimal value to the required precision.
strVal = wxNumberFormatter::ToString(min, precision, wxNumberFormatter::Style_None);
variant = min;
strVal = property->ValueToString(variant, wxPG_FULL_VALUE);
strVal.ToDouble(&min);
// Round maximal value to the required precision.
strVal = wxNumberFormatter::ToString(max, precision, wxNumberFormatter::Style_None);
variant = max;
strVal = property->ValueToString(variant, wxPG_FULL_VALUE);
strVal.ToDouble(&max);
}