I am using the following code:
string new = old.Substring(0,2).TrimStart('0') + "." + old.Substring(2,2).TrimStart('0');
to convert as follows:
0101 >> 1.1
99.10 >> 99.1
99.01 >> 99.01
The problem is that the following conversion does not work correctly:
0100 >> 1.0
Is there an easy way I could fix this. I can’t understand why it does not convert correctly. It’s important for me to have the “.0” after the one. When I run the above all I see is “1.”
TrimStart will always remove ALL 0s that the string starts with. So your second part ends up being:
which will always yield empty string.
Try this instead to ensure you always get that 0: