• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Prevent Double value being converted to N.NNNNNNE+NN in result

I have this rather simple statement:

... double.TryParse(p.ToString(), out q) ...

p.ToString() is 123400000000000000
q is 1.234E+18

q is declared as a double. I need q to be stored as '123400000000000000' because I need to package it to a web service later and the java based web service is crapping out because it does not see '1.234E+18' as a double.
  • 3
  • 3
1 Solution
Surendra NathTechnology LeadCommented:
ok you can do this dirty little trick....
but remember the number of digits will be constant in this case

double.TryParse(p.ToString("#####################"), out q)

Open in new window

CodeWranglerAuthor Commented:
ToString() does not take arguments....

Edit: 'p' is an object, actually a datarow, so a more accurate representation of the code is

Surendra NathTechnology LeadCommented:
Hi codewrangler

did the .Net through an compilation issue, when you try to give this....
Actually C# will accept the arguments, although it will not be shown in the intellisense.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

CodeWranglerAuthor Commented:
this has not fixed the problem, but i can get your suggestion to work if i do this... :)

double.TryParse(p[1].ToString().ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat), out q)

however, as i mentioned, the double value is still in scientific notation....
Surendra NathTechnology LeadCommented:
Ok, if you want to Q to be stored in the decimal not in the scientific notation (e+100) then, it is not going to happen as it is internal to MS on how it stores a variable value inside a double storage type ( we cannot really change it).

But if you can send it as a string to the calling webservice then you can do so by converting it to a string by using tostring() function and the format specifier as I said above, before you send to the webservice.
CodeWranglerAuthor Commented:
yeah, i was afraid of that. problem is that the class that VS2010 autogenerated for the webservice has the element strictly defined as Double. So my hands are tied on that one....
Gustav BrockCIOCommented:
The double output is as expected.

> the java based web service is crapping out because it does not see '1.234E+18' as a double.

No, that's a string representation of the value. So either the Java service expects a numeric integer string or you are sending a string but don't format it as needed.

>  .. the element strictly defined as Double.

If you want a numeric and integer output, use Int64:

            Int64 i;
            i = Convert.ToInt64(p);

As I guess you have no control over the Java service, perhaps you will have to modify your service to output an Int64. It should not be that difficult.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now