Reputation: 27
I want to format my number from the left side.
Suppose I have 00.524
, then it should give me 0.524
.
If I have 10.524
, then it should convert it to 10.524
.
This means if I have 0
at the start, I should remove the zero.
Is there any string format like 0:n2
for this?
Upvotes: 1
Views: 229
Reputation: 12458
Assuming you'll always have a valid double value, you can do that:
string.Format("{0:n2}", double.Parse(stringWithNumber));
Upvotes: 2
Reputation: 37533
You'll need to use a custom format specifier like:
myDouble.ToString("#0.###")
Make sure to use a #
where you want a number to appear only if it is valid and a 0 to appear anywhere you want a zero to appear otherwise.
Upvotes: 1