Is there some simpler way to check if the variable is a single digit or two digit

Hi Team,

I might have any of the value in the variable (number of months) as an input: - 1 ,2 , 3, 4 ,5 ,6 ,7 ,8, 9, 10, 11, 12

Input:- InputVar,
Output:- “00”+InputVar

Eg:- (Single digit input)
InputVar- 4 then Output= 004
InputVar- 6 then Output= 006
InputVar- 9 then Output= 009

Eg:- (Two digit input)
InputVar- 10 then Output= 010
InputVar- 11 then Output= 011
InputVar- 12 then Output= 012

I know it is straight forward but I need a help in having most optimized approach.

Thanks and Regards,

1 Like

yah we can find with length of the values in the input
and if its length is 1 like

inputvar.ToString.Length = 1
outputvar = “00” + inputvar ;
outputvar = “0”+inputvar;

hope this would help you
Cheers @hacky

1 Like

That’s convenient approach.
Didn’t click me.
Thanks Buddy.

1 Like

No worries
Cheers @hacky

1 Like

Hi @hacky

A better approach would be to use this code…

NumericValue.ToString.PadLeft(3, "0"c).ToString

This will assign a zero in front of it in a single line without the need of IF conditions.

input: 5 it will return 005
input 25 it will return 025

Hope it helps…

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.