Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get 0 in front of any number?

Tags:

I would like to append 0 before a number if it is single digit. For example it should be 01,02,03... 09, 10, 11, ...

like image 393
KoolKabin Avatar asked Jun 23 '10 14:06

KoolKabin


People also ask

How do you keep a zero in front of a number?

Use the apostrophe character You can type an apostrophe (') in front of the number, and Excel will treat it as text.

How do I get a zero in front of a number in Excel?

Use the "0"# format when you want to display one leading zero. When you use this format, the numbers that you type and the numbers that Microsoft Excel displays are listed in the following table. Example 2: Use the "000"# format when you want to display three leading zeros.

Can you start a number with 0?

Zero (0) is used as a number and also as the numerical digit. Zero gives the additive identity of the integers, real numbers, and many algebraic structures. It is used as a placeholder for writing numbers. Natural numbers start from 1, then 2 and so on.


2 Answers

Dim yourNumber as Int32 = 5 yourNumber.ToString("D2") '= "05" 
like image 152
Tim Schmelter Avatar answered Sep 29 '22 13:09

Tim Schmelter


Try this:

myNum.ToString().PadLeft(2, "0"); 
like image 24
jvenema Avatar answered Sep 29 '22 12:09

jvenema