{

How to find integer numbers length in Dart?| Flutter By Example


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.

How to find the length of a number string in Dart?

There are many ways to find the length of an integer in a dart

The below program explains about The first way, 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 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;
}

Conclusion

Learn how to get the size of an integer in dart with examples.

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.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.





Related posts

Dart| Flutter How to: Find a Given String is numeric or not

How to iterate loop Enum in Dart | Get Enum with index in Flutter By Example

Dart Enum comparison operator| Enum compareByIndex example| Flutter By Example

Dart tutorial examples/ Flutter By Examples

How to add Methods or Values to Enums in Dart | Flutter By Example

How to convert Double to Integer or Integer to double in Dart| Flutter By Example

How to: Enum to String in Dart | Print Enum name as String in Flutter By Example