My problem is, I am trying to format a number into a certian format.

The number is 100072305608500 (this is the exact copy from what was passed in)

the format it should be in is 100/07-23-056-08W5/00

I am using

return (string.Format("{##0/00-00-000-00W0/##}}", Convert.ToInt64(wellLocation)));

where the # are optional digits.
I keep getting an error "Format Exception was unhandled Input string was not in correct format.

Any help is appreciated.

Thanks in advance.

This works for me.

long number = 100072305608500L;
string format = "##0/00-00-000-00W0/##";
string output = number.ToString(format);

Leave out the curly braces in your format.
Tried this and it worked:

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            Int64 i = 100072305608500;

Thank you very much! I have it working now with your help. The funny thing is, I have a prevoiuse one for a different number working

return (string.Format("{0:##-00-000-00W0}}", Convert.ToInt32(wellLocation)));

but I couldnt get this one working.

Thanks again.


the error in your posted codeline is, that there are to much closing braces }}

try this:

return (string.Format("{0:##-00-000-00W0}", Convert.ToInt32(wellLocation)));

hope this helps

Edited 6 Years Ago by DanielGreen: n/a

This question has already been answered. Start a new discussion instead.