double_literal_format
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).
Why use this rule
Section titled “Why use this rule”.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 arrivesconst scale = 0.50; // the trailing zero says nothingconst ratio = 00.5; // a typo under any styleconst opacity = 0.5;const scale = 0.5;const ratio = 0.5;
const padding = 16.0; // a single trailing zero is significant, never reportedEnabling this rule
Section titled “Enabling this rule”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: double_literal_format: enabled: trueOptions
Section titled “Options”many_lints: rules: double_literal_format: leading_zero: true trailing_zero: falserules: 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.
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: double_literal_format: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”format_comment— Write comments as capitalised, terminated sentences.avoid_inconsistent_digit_separators— Group digit separators at a regular interval.format_test_name— Hold test descriptions to a house pattern.always_pass_global_key— Don’t create a GlobalKey inside build.