The simplest logic you can refer is as per this method i have displayed below :-
private string GetFormattedString(string strInput)
{
string strOutput = string.Empty;
if (strInput.Contains("."))
{
string[] arrInpt = strInput.Split(new char[] { '.' });
if(arrInpt.Length == 3){
if (arrInpt[0].Length == 1) strOutput = strOutput + "0" + arrInpt[0]; else strOutput = strOutput + arrInpt[0];
if (arrInpt[1].Length == 1) strOutput = strOutput + "0" + arrInpt[1]; else strOutput = strOutput + arrInpt[1];
if (arrInpt[2].Length == 1) strOutput = strOutput + "0" + arrInpt[2]; else strOutput = strOutput + arrInpt[2];
}
}
return strOutput;
}
We need to validate the string which will be passed as input to this method before passing if it is in correct format or not then it will return the desired string as output.
Hope this will be of help to you.