View Issue Details

IDProjectCategoryView StatusLast Update
0004682JEDI VCL00 JVCL Componentspublic2009-07-08 14:57
ReportercguserAssigned Toobones 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.36 
Target VersionFixed in Version3.38 
Summary0004682: TJvValidateEdit: Issues with DisplayFormat of dfFloat with DecimalPlaces
DescriptionIf DisplayFormat is set as dfFloat, and DecimalPlaces is 2, the following will happen:

JvValidateEdit1->AsFloat = 220.0;
double ValueInEdit = JvValidateEdit1->AsFloat;

ValueInEdit == 22000.0; // This evaluates to TRUE!!!

Seems that internal value is being *multiplied* by DecimalPlaces.
TagsNo tags attached.

Activities

obones

2009-02-02 01:31

administrator   ~0015281

Please provide the zipped sources of a sample application showing this

cguser

2009-02-02 10:01

reporter   ~0015285

Ok, there was a missing critical piece of information:
- DecimalSeparator is adjusted *after* component creation.


On TJvCustomValidateEdit::SetDisplayFormat,


procedure TJvCustomValidateEdit.SetDisplayFormat(NewValue: TJvValidateEditDisplayFormat);
(...)
    if (OldFormat in [..., dfFloat, ...]) and
      ... then
      SetAsFloat(JvSafeStrToFloatDef(FEditText, 0))



there is this call to JvSafeStrToFloatDef, which will call

GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, FormatSettings);

setting aDecimalSeparator as FormatSettings.DecimalSeparator

This will happen during component creation. The problem that I face comes from using a runtime VCL translator tool (Multilizer), that will reset local DecimalSeparator.

Therefore, the issue can be reproduced like this:

  DecimalSeparator = ','; // Let's say that Windows local system is set this way
  TJvValidateEdit *JvValidateEdit1 = new TJvValidateEdit(this);
  JvValidateEdit1->Parent = this;
  JvValidateEdit1->DisplayFormat = dfFloat;
  JvValidateEdit1->DecimalPlaces = 2;

  DecimalSeparator = '.';
  JvValidateEdit1->AsFloat = 220.0;
  // JvValidateEdit1->AsFloat is now equal to 22000.00


For now as a quick "fix", I'm reverting the code from
  SetAsFloat(JvSafeStrToFloatDef(FEditText, 0))
and
  Result := JvSafeStrToFloatDef(FEditText, 0);

into
  SetAsFloat(StrToFloatDef(FEditText, 0))
and
  Result := StrToFloatDef(FEditText, 0);

because setting an explicit ignore on the translator tool for TJvValidateEdit classes is not quite working as expected, yet...

2009-02-02 10:02

 

Project1.7z (3,177 bytes)

obones

2009-07-08 14:57

administrator   ~0015781

The problem, in the current version, was that CheckChars still contained the old value of DecimalSeparator.
I have introduced in SVN a new public method called RecalcCheckChars that allows to force rereading DecimalSeparator when it has changed.

Issue History

Date Modified Username Field Change
2009-01-30 06:28 cguser New Issue
2009-02-02 01:28 obones Status new => acknowledged
2009-02-02 01:31 obones Note Added: 0015281
2009-02-02 01:31 obones Status acknowledged => feedback
2009-02-02 10:01 cguser Note Added: 0015285
2009-02-02 10:02 cguser File Added: Project1.7z
2009-07-06 14:04 obones Status feedback => acknowledged
2009-07-08 14:57 obones Note Added: 0015781
2009-07-08 14:57 obones Status acknowledged => resolved
2009-07-08 14:57 obones Fixed in Version => Daily / SVN
2009-07-08 14:57 obones Resolution open => fixed
2009-07-08 14:57 obones Assigned To => obones