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 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.

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

```
3
3
```

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];
print(decimalsCount.length);
}
```

Output is

```
4
```

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.

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.

🧮 Tags

Recent posts

How to measure time taken by function to execute Dart|Flutter measure Dart| Flutter How to: Find a Given String is numeric or not Why the main method is declared as static in java? What is the use of javap command in java? what is the difference between derby and MySQL databaseRelated posts