0

Basically I am formatting a string so that it has a specific set of 0's and is done so like the following for any data type that is NOT already a string:

string weight = Convert.ToDouble(item.Weight).ToString("00000.000",CultureInfo.InvariantCulture).Replace(".", "");

Where item.Weight is a string value.

However I want to do this without double handling by converting to a double then back to a string just so I can use CultureInfo.InvariantCulture with the ToString method? Is there another way I can do this? As I cannot call a ToString on a string.

Thanks in advance

Mark
  • 501
  • 2
  • 11
  • 28
  • [String.ToString()](https://msdn.microsoft.com/en-us/library/29dxe1x2%28v=vs.110%29.aspx) does not allow to format numbers, so the conversion to a double is necessary. – Georg Patscheider Apr 05 '16 at 08:52
  • You could try [String.Format()](https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx) method – bkdev Apr 05 '16 at 08:56

1 Answers1

-1

This should do: Convert.ToDouble(item.Weight).ToString("#.##0")

Zalomon
  • 553
  • 4
  • 14