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

Format integer to be at least X digits by adding trailing zeroes

Is there a way to format an integer to be at least X digits by adding trailing zeroes? Such that with X being 4 I would get:

4 -> 4000
58 -> 5800
372 -> 3720
5432 -> 5432
12345678 -> 12345678

I know how to write a helper function to achieve this, just wondering if there is a built-in string formatting method to do the same.

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

>Solution :

int intValue = 20;
int x=4;
int.parse(intValue.ToString().PadRight('0',x))

Something like this should work

Check the syntax.

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