View Issue Details

IDProjectCategoryView StatusLast Update
0034370LazarusOtherpublic2018-10-21 18:54
ReporterwpAssigned ToBart Broersma 
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version2.0.1 (SVN)Fixed in Version2.0.1 (SVN) 
Summary0034370: FloatSpinEditEx truncating decimals
DescriptionIf the value of pi (3.1415926563) is assigned to the Value of a TFloatSpinEditEx in the OnCreate event, the string "3.14" is displayed initially - which is correct because the default value of the DecimalPlaces is 2. But if the DecimalPlaces are incremented later only zeros are added to the 3.14.

On the other hand, when pi is assigned to the FloatSpinEditEx later when the form is fully created, the real digits are added to 3.14
Steps To ReproduceThe attached demo contains a TFloatSpinEditEx loaded with the value of pi.

The form contains also a TSpinEditEx which is used to change the number of DecimalPlaces of the FloatSpinEditEx, as well as a TButton.

1st test:
The OnCreate event of the form sets its value to pi -> when the form is completely created and shown the string "3.14" is displayed. When the DecimalPlaces are incremented the string becomes "3.140", "3.1400" etc.

2nd test:
Click on the button which sets pi to the FloatSpinEditEx.Value, too, but, of course, only when the form is fully created. Incrementing the DecimalPlaces now addes the correct digits to the "3.14" ("3.142", "3.1416", etc).
TagsNo tags attached.
Fixed in Revisionr59332
Attached Files



2018-10-01 22:40

developer (2,062 bytes)

Bart Broersma

2018-10-02 16:40

developer   ~0111208

@wp: After we discussed this yesterday on ML, I gave it another thought.
Given Decimals := 2 and you assign Value := Pi, Increment := 1.0, what would be the expected result when user presses Up-spin one time?
Should it be Pi + 1.0 (4.1415926536) or 4.14?

IIRC I designed it to be the latter.
But if this is couter-intuitive, it can be changed.


2018-10-02 18:53

developer   ~0111212

Floating point numbers can have an "infinite" number of decimal places. Therefore the value stored in the FloatSpinEditEx.Value must be full precision, irrespective of the settings of DecimalPlaces which is just used for nice formatting.

Or in other words: changing the DecimalPlaces should only change FloatSpinEditEx.Text, but not its .Value.

Suppose I assign the value of pi to the Edit and want to calculate sin(FloatSpinEditEx.Value) - then I'd expect to get the same result as sin(pi) = 0, but not sin(3.14) = 0.00159...

Returning to you question: When Value=pi, Decimals=2 and Increment=1, then the first up-spin should result in a Value of pi+1 = 4.142582..., but the edit should display 4.14 (i.e. FloatSpinEditEx.Text = '3.14', but FloatSpinEditEx.Value = 4.141592...).

Bart Broersma

2018-10-02 19:36

developer   ~0111213

Last edited: 2018-10-02 19:47

View 3 revisions

Then again, the control is designed for manual input of numbers, not for semi-arbitrary precision.

B.t.w. with a TFloatSpinEdit when I do Value := Pi; writeln(Value), the output is 3.1400000000000 (Decimals = 2).
So, TFloatSpinEdit also does not behave like you desire.
And since D7 does not have such a control I cannot test how Delphi behaves.


2018-10-02 20:12

developer   ~0111216

> Then again, the control is designed for manual input of numbers, not for semi-arbitrary precision.

I see it more general. The SpinEditEx controls are very well designed and appear to me the ideal numerical Lazarus edit components - except for this bug (in my eyes).

A possible derived component, for example, could use the fpexpression parser or could open a calculator like in TCalcEdit to calculate a formula like "sqrt(2)". The result would be very much in error if Value would return only the rounded precision.

Bart Broersma

2018-10-02 22:56

developer   ~0111219

Last edited: 2018-10-02 22:58

View 2 revisions

Well, I did not design it with that in mind.
I designed it because of the flaws of T(Float)SpinEdit, as described in the comments at the top if the source file.
I specifically wanted it to return the value that you see in the text.

The use case you mentioned IMO does not fit the purpose of a TFloatSpinEdit(Ex).
IMO it was designed to give users a simple method of inputting floating point values, with a precision specified by the designer.

PS. I might be unable to respond for the next day, my computer needs repairing.


2018-10-02 23:29

developer   ~0111220

Last edited: 2018-10-03 11:06

View 3 revisions

I see the point.

But the issue of the report remains: When FloatSpinEditEx.Value is set to pi in the OnCreate event then the value is rounded. But when this is done in a ButtonClick it is not.

So, when we agree on your concept of rounding then the ButtonClick behavior is wrong.

Bart Broersma

2018-10-04 12:36

developer   ~0111236

That is strange.
I gather you mean OnCreate of the form?

If you query the value of the control, and it does not have a handle yet, it will return FValue "uncesored" (Pi in this case). After handle creation it should always return the value that is represented by the text.

I tested code like this in a buttonclick:
Value := Pi
--> gives 3.14 (as expected)
Tested on Windows

I cannot test right now.
I have no machine where I can run Lazarus.
Maye in a few days.


2018-10-04 13:42

developer   ~0111237

Ah - Now I do this:
(1) Click "Set pi" to set Value to pi
(2) Click another button to query the value and display it in a msg box
      ShowMessage(Format('%.*f', [FloatSpinEditEx1.DecimalPlaces, FloatSpinEditex1.value));
(3) Increase DecimalPlaces
--> the edit displays '3.140', '3.1400', etc.

When step (2) is missing the edit displays '3.142', '3.1416', etc.

Bart Broersma

2018-10-05 16:05

developer   ~0111263

Hmm, interesting.
GetValue also updates FValue, and I guess SetDecimalPlaces does not query Vlaue before incrementing DecimalPlaces.

Given my previous remarks, '3.140' would be the coreect value (to be consitent).

I'll see if I can set up another machine this weekend.
(My old Celeron@700MHz/512MB/Debian8 is not usable for development)

Just curious: how does a TFloatSpinEdit behave in this case?


2018-10-05 16:51

developer (2,301 bytes)


2018-10-05 16:55

developer   ~0111265

Added a v2 of the demo which contains a TFloatSpinEdit in addition to the TFloatSpinEditEx - both get the same commands.

TFloatSpinEdit behaves almost correct (in our now agreed definition) and always truncates Value to the given number of decimals places. However, if DecimalPlaces is 1 or 2 then it increments this value by 1 - strange...

Bart Broersma

2018-10-21 15:30

developer   ~0111496

Fixed as suggested in note 0111263.
Please test and close if OK.


2018-10-21 18:54

developer   ~0111501


Issue History

Date Modified Username Field Change
2018-10-01 22:39 wp New Issue
2018-10-01 22:40 wp File Added:
2018-10-01 22:40 wp Assigned To => Bart Broersma
2018-10-01 22:40 wp Status new => assigned
2018-10-01 22:55 wp Summary FloatSpinEditEx truncating the value of pi => FloatSpinEditEx truncating decimals
2018-10-02 16:40 Bart Broersma Note Added: 0111208
2018-10-02 18:53 wp Note Added: 0111212
2018-10-02 19:36 Bart Broersma Note Added: 0111213
2018-10-02 19:40 Bart Broersma Note Edited: 0111213 View Revisions
2018-10-02 19:47 Bart Broersma Note Edited: 0111213 View Revisions
2018-10-02 20:12 wp Note Added: 0111216
2018-10-02 22:56 Bart Broersma Note Added: 0111219
2018-10-02 22:58 Bart Broersma Note Edited: 0111219 View Revisions
2018-10-02 23:29 wp Note Added: 0111220
2018-10-03 11:04 wp Note Edited: 0111220 View Revisions
2018-10-03 11:06 wp Note Edited: 0111220 View Revisions
2018-10-04 12:36 Bart Broersma Note Added: 0111236
2018-10-04 13:42 wp Note Added: 0111237
2018-10-05 16:05 Bart Broersma Note Added: 0111263
2018-10-05 16:51 wp File Added:
2018-10-05 16:55 wp Note Added: 0111265
2018-10-21 15:30 Bart Broersma Fixed in Revision => r59332
2018-10-21 15:30 Bart Broersma LazTarget - => 2.0
2018-10-21 15:30 Bart Broersma Note Added: 0111496
2018-10-21 15:30 Bart Broersma Status assigned => resolved
2018-10-21 15:30 Bart Broersma Fixed in Version => 2.0.1 (SVN)
2018-10-21 15:30 Bart Broersma Resolution open => fixed
2018-10-21 15:30 Bart Broersma Target Version => 2.0.1 (SVN)
2018-10-21 18:54 wp Note Added: 0111501
2018-10-21 18:54 wp Status resolved => closed