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
Julia examples - Variable Type Nim example - Convert String to/from the Int How to get length of an array and sequence in Nim? Nim environment variables - read, set, delete, exists, and iterate examples? How to convert from single character to/from string in Nim?Related posts