Given a decimal value, how can I add a leading zero in a string only when a value is less than 1?
Eg.
.20 -> "0.20" - Add a leading 0
1.20 -> "1.20" - Value remains the same
The value before the decimal place could be of any length and the value after the decimal place will only be 2 digits ie. currency. Is this achievable with String.Format()? Or should I rely on a basic if statement?
The String.Format() documentation is rather confusing to me.
I've checked several other questions/answers and can't seem to find what I'm looking for.
EDIT: As mentioned by several answers, this kind of leading zero addition should be the default behavior of the ToString() method called on a value. For whatever reason, that isn't happening in my case, so The String.Format() is necessary in my case.