Skip to main content

double-literal-format

added in: 1.6.0
⚙️🛠
Free+

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 (example).

analysis_options.yaml
dart_code_metrics:
rules:
- double-literal-format:
explicit-trailing-zero: false

Example

❌ Bad:

// LINT: Avoid redundant leading '0' in double literals. Try removing it.
var a = 05.23, b = 03.6e+15, c = -012.2, d = -001.1e-15;

// LINT: Avoid missing leading '0' in double literals. Try adding it.
var a = .257, b = .16e+5, c = -.259, d = -.14e-5;

// LINT: Avoid redundant trailing '0' in double literals. Try removing it.
var a = 0.210, b = 0.100e+5, c = -0.250, d = -0.400e-5;

✅ Good:

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

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

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

Example with "explicit-trailing-zero"

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

❌ Bad:

// LINT: Prefer double literals to int literals. Try adding a trailing '0'.
final double value = 1;

✅ Good:

final double value = 1.0;