In this article, We will discuss about How to add Trailing Zeros in a String in C#.
Well, there will be Situation while development or sometimes client requirement to add Trailing Zeros to particular String and display in a Grid or SomeWhere else.
To implement Trailing Zeros in String, We have a PadRight() exist which will do the Work for Us.
PadRight() takes 2 parameters as int totalWidth(Total Width of String) and char paddingChar(Replaced by Which Char).
Let me take an example to implement Trailing Zeros.
Example:-
---------------
1/
string strNumber="123";
In this strNumber, We will apply the Trailing Zeros and Which is given below,
string strTrailingNumber=strNumber.PadRight(6,'0');
So, the output of strTrailingNumber is "123000".
2/
string strNumber="";
In this strNumber, We will apply the Trailing Zeros and Which is given below,
string strTrailingNumber=strNumber.PadRight(6,'0');
So, here the output of strTrailingNumber is "000000".
0 comments:
Post a Comment