KT.UNDERSCORES_IN_NUMERIC_LITERALS

Long base 10 numbers not separated with underscores

This rule detects and reports long base 10 numbers which should be separated with underscores for readability. For Serializable classes or objects, the field serialVersionUID is explicitly ignored. For floats and doubles, anything to the right of the decimal point is ignored.

Noncompliant Code

Copy
const val DEFAULT_AMOUNT = 1000000

Compliant Code

Copy
const val DEFAULT_AMOUNT = 1_000_000

Options

  • acceptableLength (default: 4)

    Maximum number of consecutive digits that a numeric literal can have without using an underscore

  • allowNonStandardGrouping (default: False)

    If set to false, groups of exactly three digits must be used. If set to true, 100_00 is allowed.

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html