Skip to main content

double-literal-format

added in: 1.5.0
⚙️🛠

Checks that double literals should begin with 0. instead of just ., and should not end with a trailing 0. Helps keep a consistent style of numeric literals and decrease potential typos.

⚙️ Config

Set explicit-trailing-zero (default is false) to require one trailing 0.

dart_code_metrics:
...
rules:
...
- double-literal-format:
explicit-trailing-zero: true

Redundant leading '0'

❌ Bad:

  var a = 05.23, b = 03.6e+15, c = -012.2, d = -001.1e-15;

✅ Good:

  var a = 5.23, b = 3.6e+15, c = -12.2, d = -1.1e-15;

Literal begin with '.'

❌ Bad:

  var a = .257, b = .16e+5, c = -.259, d = -.14e-5;

✅ Good:

  var a = 0.257, b = 0.16e+5, c = -0.259, d = -0.14e-5;

Redundant trailing '0'

❌ Bad:

  var a = 0.210, b = 0.100e+5, c = -0.250, d = -0.400e-5;

✅ Good:

  var a = 0.21, b = 0.1e+5, c = -0.25, d = -0.4e-5;