Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format integer as string with 2 digits?

Tags:

format

vb.net

I would like to format an integer 9 to "09" and 25 to "25".

How can this be done?

like image 845
AntonioC Avatar asked Dec 19 '22 21:12

AntonioC


1 Answers

You can use either of these options:

The "0" Custom Specifier

  • value.ToString("00")
  • String.Format("{0:00}", value)

The Decimal ("D") Standard Format Specifier

  • value.ToString("D2")
  • String.Format("{0:D2}", value)

For more information:

  • Custom Numeric Format Strings
  • Standard Numeric Format Strings
like image 96
Reza Aghaei Avatar answered Dec 27 '22 12:12

Reza Aghaei