I have a dataframe where the have different total digits. How do I add leading zeroes when different rows need a different number of leads to achieve the max 3 digits if digits beofre decimal point less than 3.
id col1
1 A 8
2 B 125.4
3 C 27.1
4 E 2998
5 F 12341
6 G 7.2
7 F 6.52
Desired Output
id col1 col2
1 A 8 008
2 B 125.4 125.4
3 C 27.1 027.1
4 E 2998 2998
5 F 12341 12341
6 G 7.2 007.2
7 F 6.52 006.52
I've read many solutions in Add leading zeros to numeric variable to the left of the decimal point if value is less than a specific length but have not yet solve my problem.Any help is much appreciated.