Skip to content

Conversation

@flofriday
Copy link
Contributor

There are some quite a few ways numbers can be expressed in Kotlin which previously weren't supported and with this commit conforms to the grammar described in the Kotlin Language Specification.

Separators

Like Java Kotlin allows any amount of separators inside number literals, as long as they don't appear at the start or end.

9_000
1__2
1_2.3_4E5_6

Plus and minus in E-Notation is optional

While plus and minus can occur after the e or E it's not required.

123.123e123
123.123E123
123.123e+123
123.123E+123
123.123e-123
123.123E-123

Binary Literals

Just as in Java there are binary literals which start with the 0b or 0B prefix.

0b011010
0B011010

Suffixes

Kotlin allows the suffixes f, F, L, u, U, uL, UL, though notably the previously supported suffix l is not allowed.

123u
123U
123L
123uL
123UL
123f
0003f
0b01L
0xFF8800L
0XFF8800L
0b01uL
0xFF8800uL
0XFF8800uL
0b01UL
0xFF8800UL
0XFF8800UL

@alecthomas alecthomas merged commit 1074a2a into alecthomas:master Oct 6, 2025
2 checks passed
@alecthomas
Copy link
Owner

Thanks! Apologies for the delay, I've been travelling!

@flofriday
Copy link
Contributor Author

No problem, thanks for maintaining the library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants