Solved

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

Posted on 2014-02-12
7
354 Views
Last Modified: 2014-02-19
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.
0
Comment
Question by:CodeWrangler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39854504
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

0
 

Author Comment

by:CodeWrangler
ID: 39854537
ToString() does not take arguments....

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

p[1].ToString()
0
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39854565
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.
0
Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

 

Author Comment

by:CodeWrangler
ID: 39854674
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....
0
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39854712
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.
0
 

Author Comment

by:CodeWrangler
ID: 39854718
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....
0
 
LVL 51

Expert Comment

by:Gustav Brock
ID: 39861386
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.

/gustav
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question