Skip to content

double_literal_format

v1.0.0WarningFixConfigurableFormatting

This rule flags a double literal written with a missing leading zero (.5), a redundant leading zero (00.5), or a redundant trailing zero (0.50).

.5 and 0.50 denote exactly the same numbers as 0.5, so the spelling carries no information and only costs the reader a moment deciding whether it does.

The bare-dot form is the one that actually misleads: .5 reads as a member access until the eye reaches the digit, and a single dropped character turns .5 into an identifier that may still parse.

dart format normalizes none of these, so this rule does not fight the formatter.

A single trailing zero is never reported. 1.0 cannot lose it without becoming 1. (invalid Dart) or the integer 1 (a different type) — and in Flutter code, where 16.0 and 0.0 are everywhere, reporting them would make the rule unusable.

This rule is in the pedantic preset: literal spelling is a house style.

See also: Dart language tour — numbers

const opacity = .5; // reads as a member access until the digit arrives
const scale = 0.50; // the trailing zero says nothing
const ratio = 00.5; // a typo under any style
const opacity = 0.5;
const scale = 0.5;
const ratio = 0.5;
const padding = 16.0; // a single trailing zero is significant, never reported

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
double_literal_format:
enabled: true
analysis_options.yaml
many_lints:
rules:
double_literal_format:
leading_zero: true
trailing_zero: false
Option Type Default Description
leading_zero bool true Whether .5 must be written 0.5
trailing_zero bool true Whether 0.50 must be written 0.5

A redundant leading zero (00.5) is reported even with leading_zero: false. That option governs whether .5 is acceptable, which is a style choice; 00.5 is a typo under either style.

To disable this rule:

many_lints.yaml
rules:
double_literal_format: false

To keep the rule on but skip certain paths, use per-rule exclude.