THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.
This tutorial shows you how to find integer number lengths in Dart.
For example, if the given number is 12345, Then the length of a number is 5.
There are many ways to find the length of an integer in a dart
The below program explains about
The first way is, Convert the integer to a string using the toString()
method
Call length property to return the length of a string.
The second way, convert a number to a String using interpolation syntax. Call length property
void main() {
int num = 123456;
print(num.toString().length); // 6
print('$num'.length); // 6
print(1231456.length()); // 7
}
extension NumberLength on num {
int length() => this.toString().length;
}
Another way is to write an Extension on the num type
Added the length method that returns the string length.
void main() {
print(1231456.length()); // 7
}
extension NumberLength on num {
int length() => this.toString().length;
}
Learn how to get the size of an integer in a dart with examples.
🧮 Tags
Recent posts
Ways to skip test case execution in Gradle project build Learn Gradle | tutorials, and examples How to run only single test cases with Gradle build How to print dependency tree graph in Gradle projects How to perform git tasks with build script?Related posts