Link to home
Start Free TrialLog in
Avatar of mathieu_cupryk
mathieu_cuprykFlag for Canada

asked on

Make two digits if 0 then 00 if 1 then 01.

dt.Rows[row].ItemArray[0].ToString();

I have to format this numeric value two places.
two 1 -> 01
       2 -> 02
       4->  04
     10-> 10
     11-> 11
 

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this will do:
http://msdn.microsoft.com/en-us/library/system.string.padleft(VS.71).aspx
dt.Rows[row].ItemArray[0].ToString().PadLeft(2, "0")

Open in new window

Avatar of YellowShoe
YellowShoe

Console.Write("{0:D2}", Variable);

ref: http://msdn.microsoft.com/en-us/library/s8s7t687.aspx
Avatar of mathieu_cupryk

ASKER

C:\SvnWork\InitialPriceReporting\DotNet\InitialPriceReporting\clsGenerateReadyToLoad.cs(81,33): error CS1502: The best overloaded method match for 'string.PadLeft(int, char)' has some invalid arguments

I
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sw.Write(dt.Rows[row].ItemArray[0].ToString().PadLeft(2, '0'));
                       sw.Write(",");

I still get 1 digit.
if I look in an excel sheet.