Why is this an issue?

Long numbers, whether integral or floating-point, can be difficult to read and understand at a glance. This can lead to mistakes when reading, writing, or maintaining code. For example, it’s easy to miscount the number of zeros in a large number or misplace a decimal point. These mistakes can introduce subtle bugs that are hard to detect and debug.

To improve readability, Rust allows the use of underscores as visual separators in numeric literals. By grouping digits into more manageable chunks, numbers become easier to read and understand.

This practice reduces the likelihood of errors and makes the code more maintainable.

How to fix it

To fix this issue, use underscores to make numeric literals more explicit and easier to read.

Code examples

Noncompliant code example

let large_number = 1000000000;
let precise_float = 1234567.890123;

Compliant solution

let large_number = 1_000_000_000;
let precise_float = 1_234_567.890_123;

Resources

Documentation