Dart Example to count the number of digits in a number| Decimals Count in Dart

Dart count of digits of a number and decimal numbers

This example covers two programs in dart.

  • the first program finds the count of a number of digits in an integer number

The length of a number is to find the count of the number of digits.

For example, 129 number digits count is 3.

  • The second program finds the count of a decimal of a double number For example, 129.1234 number, decimal digit count is 4.

Consequently, Both are used to implement digit count for a given number.

How to get the count digit count of an integer number in dart and flutter

This program calculates the count of digits in a given number

  • First, the number is converted to String using the toString() method.
  • Find the length of a string using the length method
  • Another way is using interpolation string with length method

Here is a program to find the number of digits counted in a given number

void main() {
  int number = 129;

  print(number.toString().length); //3
  print('$number'.length); //3

When you run the above program, the Output is


Count of decimal places in a given number in dart and flutter

This program counts the number of decimal digits in a given double number

  • Double number is created with decimal places
  • Convert, this number to String using the toString() method
  • Next, Split the number using a dot(.) delimeter
  • Returns the decimals number as a string
  • Find the length of a string Following is an example for a function to count the number of decimal digits of a double number
void main() {
  double doubleNumber = 3.1435;
  var decimalsCount = doubleNumber.toString().split('.')[1];

Output is



Learn how to calculate digit count in a given integer number in the dart program, Also find the fractional or decimal digits count in a double number.

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
You'll get a notification every time a post gets published here.

Related posts

Dart| Flutter How to: Read pubspec.yaml attributes (version) with examples

How to Create and build a Singleton Class Dart or Flutter example| Dart By Example

What is the difference between var and dynamic and final in dart?| Flutter By Example

How to: Check if Phone number is valid or not in Dart| Flutter By Example

Dart| Flutter How to read an image from a disk and resize a file

Dart/Flutter: How to write setter and getter fields or members variables in a class with Example

Dart| Flutter How to get extension name and MIME type of a file with example