New in Symfony 3.2: Better readability for YAML numeric literals
Long numeric literals, being integer, float or hexadecimal, are known for their poor readability in code and configuration files:
1 2 3 4 5
parameters: credit_card_number: 1234567890123456 long_number: 10000000000 pi: 3.141592653589793 hex_words: 0xCAFEF00D
In Symfony 3.2, YAML files added support for including underscores in numeric literals to improve their readability:
1 2 3 4 5
parameters: credit_card_number: 1234_5678_9012_3456 long_number: 10_000_000_000 pi: 3.14159_26535_89793 hex_words: 0x_CAFE_F00D
During the parsing of the YAML contents, all the
_ characters are removed
from the numeric literal contents, so there is not a limit in the number of
underscores you can include or the way you group contents.
This feature is defined in the YAML specification and it's widely supported in other programming languages (Java, Ruby, Rust, Swift, etc.).
Deprecating comma separators in floats¶
The new underscore separator made us think about the need of the comma to separate the float number contents. Ultimately we decided to deprecate it, so starting from Symfony 3.2, the use of the comma to separate contents is deprecated:
1 2 3 4 5 6 7 8 9
parameters: # deprecated since Symfony 3.2 foo: 1,230.15 # equivalent without the comma separator foo: 1230.15 # equivalent with the underscore separator foo: 1_230.15
New in Symfony 3.2: Better readability for YAML numeric literals symfony.com/blog/new-in-symfony-3-2-better-readability-for-yaml-numeric-literalsTweet this
Become a certified developer! Exams are online and available in all countries.Register Now
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.