Review main Merged

84526[FEATURE] Make scale of TCA type number configurable

Georg Ringer CR +2 V +2 Expert +1205 −78 updated 11/04/26, 23:18

Commit message

TCA type "number" with format "decimal" always stored and rendered
exactly two decimal digits, hardcoded in the database schema, in
DataHandler and in FormEngine.

The new column configuration option "scale" makes this configurable
and replaced the "format" option:

    'config' => [
        'type' => 'number',
        'scale' => 4,
    ],

It defaults to 0 and is limited to a value between 0 and 30. The
auto created database column keeps eight digits in front of the
decimal point and adds the scale on top.

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Benni Mack +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 29

Show 9 more files

Review log 2637

Show 812 earlier messages
  1. Georg Ringer uploaded patch set 1 06/07/24, 15:15

  2. Georg Ringer uploaded patch set 2 06/07/24, 15:16

  3. core-ci voted on patch set 1 V -1 06/07/24, 15:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58880

  4. core-ci voted on patch set 2 V -1 06/07/24, 15:22 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58881

  5. Ayke Halder commented on patch set 2 06/07/24, 19:51

    Is this one here also related? https://github.com/TYPO3/typo3/blob/d3008fcd3eb3c3049049a2dbaf759b7418e95805/typo3/sysext/core/Classes/DataHandling/DataHandler.php#L1645-L1647 ```php /** * Evaluate 'number' type values * * @param mixed $value The value to set. * @param array $tcaFieldConf Field configuration from TCA */ protected function checkValueForNumber(mixed $value, array $tcaFieldConf): array { […] if ($format === 'decimal') { // @todo Make precision configurable $precision = 2; ```

    NumberElement.php:224

    `'0.' . str_repeat('0', $scale - 1) . '1'` could be replaced with `'0.' . sprintf("%'0${scale}d", 1);` or `sprintf("0.%'0${scale}d", 1);`

    DefaultTcaSchema.php:1024

    Maybe replace `0.00` with `0.0` as both are a float with value `0.0`.

    tx_styleguide_elements_basic.php:1901

    Maybe add one blank or remove them all.
  6. Garvin Hicking commented on patch set 2 02/19/26, 08:34

    Would you like to pick this up? I was just annoyed we have this hardcoded :D :D
  7. Josef Glatz commented on patch set 2 04/07/26, 08:53

    that would be a nice gem for any upcoming TYPO3 version 😊
  8. Georg Ringer uploaded patch set 3 V -1 08/27/26, 19:00

  9. Georg Ringer commented on patch set 3 08/27/26, 19:06

    This change is ready for review.
  10. core-ci voted on patch set 3 V -1 08/27/26, 20:01 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107289

  11. core-ci commented on patch set 3 08/27/26, 20:39 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107289

  12. Georg Ringer uploaded patch set 4 V -1 09/01/26, 14:37

  1. core-ci voted on patch set 3 V -1 09/01/26, 14:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107289

  2. core-ci voted on patch set 4 V -1 09/01/26, 15:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107499

  3. Georg Ringer uploaded patch set 5 V -1 09/01/26, 20:35

  4. core-ci voted on patch set 5 V +1 09/01/26, 20:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107525

  5. Garvin Hicking commented on patch set 5 V +1 09/02/26, 09:29

    Reply

    Done
    Seems to work well for me. I'm not deep into the decimal / scientific notation parsing algorithms but the code reads sane to me.

    value-slider.ts:75

    I think we should also allow "precision" as a fallback to prevent a BC of this component

    NumberElement.php:224 Reply

    Done

    DefaultTcaSchema.php:1024 Reply

    Done
  6. Daniel Windloff commented on patch set 5 09/11/26, 07:51

    Hey, very nice feature. just two remarks: - I think the coupling between TcaSchmea and other parts of the core is not beneficial. - I suggest using this feature for the columns `latitude` and `longitude` in `EXT:filemetadata/Configuration/TCA/Overrides/sys_file_metadata.php`

    NumberFieldType.php:59

    I would suggest avoiding static methods in TcaSchema and do not couple this class to FormEngine or DataHandler.

    NumberFieldType.php:62

    The scale is only valid for format decimal, otherwise it is 0
  7. Daniel Windloff commented on patch set 5 09/11/26, 09:16

    Sorry for the step-by-step response, I’ve given this some more thought. I don’t think the design of the `NumberFieldType` class is optimal, as `scale` is only valid for one specific format. From my perspective, one of the following approaches would be better: a) Use two TCA types: one for integers and one for floats. That way, only the decimal type would have the method getScale() for handling decimal places. The `format` option could vanish in both types. b) Remove `getFormat` from the class and the `format` option from the TCA. The number of decimal places would then determine whether it is an integer or a float. A TCA migration could migrate the `integer` format to 0 decimal places and the `decimal` format to 2 decimal places. Both TCA migrations only apply, if no `scale` is set. Format will be removed via TCA migration as well. Either approach would resolve the issue of the class configuration of `NumberFieldType` being over-specified. What do you think?
  8. Daniel Windloff commented on patch set 5 CR -1 09/12/26, 06:39

    On it
  9. Daniel Windloff uploaded patch set 6 CR -1 V +1 09/13/26, 04:35

  10. core-ci voted on patch set 6 V -1 09/13/26, 04:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108436

  11. Daniel Windloff uploaded patch set 7 V -1 09/13/26, 05:25

  12. core-ci voted on patch set 7 V -1 09/13/26, 05:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108440

  13. Daniel Windloff uploaded patch set 8 V -1 09/13/26, 06:25

  14. core-ci voted on patch set 8 V +1 09/13/26, 06:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/108441

  15. Daniel Windloff commented on patch set 8 09/13/26, 06:34

    Reply

    Done

    Reply

    Done

    NumberFieldType.php:59 Reply

    Done

    NumberFieldType.php:62 Reply

    Done
  16. Benni Mack uploaded patch set 9 V +1 09/30/26, 08:18

  17. Benni Mack commented on patch set 9 09/30/26, 08:20

    Reply

    Hey, I'm gonna reopen this. I wonder if the "scale" is actually the right term for this. As "precision" fits much better, or even "fraction" or "digits". WDYT?
  18. core-ci voted on patch set 9 V +1 09/30/26, 08:26 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109595

  19. Garvin Hicking commented on patch set 9 09/30/26, 08:39

    Reply

    My personal order of preference: digits > precision > fraction > scale

    value-slider.ts:75 Reply

    Done
  20. Benni Mack commented on patch set 9 09/30/26, 09:52

    Reply

    double-checked. "scale" is correct, also used in Doctrine DBAL and SQL, so we're good.
  21. Benni Mack commented on patch set 9 CR +1 V +1 09/30/26, 09:52

    we'll handle EXT:filemetadata separately. Patch is finally good to go.
  22. Garvin Hicking voted on patch set 9 CR +2 V +2 09/30/26, 09:54

  23. Garvin Hicking merged patch set 10 09/30/26, 09:54

  24. Markus Klein commented on patch set 10 11/04/26, 23:16

    DefaultTcaSchema.php:891

    This is a breaking change. Suddenly number fields with format 'decimal', which had no scale defined, will be assumed to scale=0 and therefore changed to integer in DB. The test here, written before this change, fails now: https://review.typo3.org/c/Packages/TYPO3.CMS/+/96120/4/typo3/sysext/core/Tests/Unit/Database/Schema/DefaultTcaSchemaTest.php#3397
  25. Markus Klein commented on patch set 10 11/04/26, 23:18

    DefaultTcaSchema.php:891 Reply

    I overlooked the TCA Migration. screw that comment.