Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get number of certain place of long number

How can I get a number of a certain place, for example, when I have a number like 12345, I need the number on the second place, so in this case the 2. A few more examples that you get the idea:

346775 => 4

673456 => 7

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

099784 => 9

How is this possible in Dart/Flutter?

>Solution :

You can convert the number to a String and get the element at index 1 from the String.

void main() {
  final int longNumber = 12345;  
  final int numberAtSecondPlace = int.parse(longNumber.toString()[1]);
  
  print(numberAtSecondPlace); //2
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading