issue of assigning a double variable in .net.

V

Valli

Hi,

I have an issue of displaying a double variable in .net.

I receive a double data through socket from C project into .net. The value
entering is 2010030550004850.
But it gets stored as 2.01003055000485E+15. I need the original value.
How can I do this? Can anyone help me out

--
Thanks & regards,

V.Valli


This e-mail and any files transmitted with it are for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. If you are not the intended recipient, please contact the
sender by reply e-mail and destroy all copies of the original message.

Any unauthorized review, use, disclosure, dissemination, forwarding,
printing or copying of this email is strictly prohibited and may be
unlawful.
 
P

PvdG42

Valli said:
Hi,

I have an issue of displaying a double variable in .net.

I receive a double data through socket from C project into .net. The
value entering is 2010030550004850.
But it gets stored as 2.01003055000485E+15. I need the original value.
How can I do this? Can anyone help me out
The value was stored in "E-notation" in the C program as well, and the value
is the same. Typically, you would display the value as a string, using
whatever formatting you deem appropriate. How are you attempting to display
the value?
The .NET Double structure includes a ToString() method designed to help you.

http://msdn.microsoft.com/en-us/library/system.double_members.aspx
 
P

Patrice

They are the same value. It seems you are confusing how the variable is
really stored in memory and its text representation (the default is
"G"eneral which is the shortest between fixed point and scientific notation)
..

For example here if I display a variable to which I assigned 1.2, I'll see
1,2. But the underlying value is stored the same than on every other
computer on earth. It is just that the text representation for my country
uses a comma rather than a dot.

You can control the format used to display the value using
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx but knowing more about
the context could help (for example if you display this in a form, you have
form mechanism for formatting).

Try the "f" format or perhaps a custom format depending on how you want to
handle decimal places...
 
V

Valli

I need to update this value in database in numeric datatype.
The .tostring() methods also returns the value in exponent form only.

--
Thanks & regards,

V.Valli


This e-mail and any files transmitted with it are for the sole use of the
intended recipient(s) and may contain confidential and privileged
information. If you are not the intended recipient, please contact the
sender by reply e-mail and destroy all copies of the original message.

Any unauthorized review, use, disclosure, dissemination, forwarding,
printing or copying of this email is strictly prohibited and may be
unlawful.
 
F

Family Tree Mike

Valli said:
I need to update this value in database in numeric datatype.
The .tostring() methods also returns the value in exponent form only.

That's true, but if you use the overload value.ToString("f0"), you get the
value without the exponentiation. The zero can be replaced with the number
of decimal places desired.

Mike
 
P

Patrice

I need to update this value in database in numeric datatype.
The .tostring() methods also returns the value in exponent form only.

A best practice is to used parameters rather than using a string inside a
SQL statement :
- you'll be less sensitive to SQL injection attacks
- you could have the same problem with the decimal separator and dates and
even strings (if the string includes a ' character).

See :
http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx

The key thing to realize is that you almost never see the real value. A date
and even a decimal value are allways shown according to a text
representation that depends on the country etc... Using parameters takes
care of "transporting" the value under a culture insensitive format. Else
you have to do this job yourself...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Round(0.5) returns 0. 7
needs double value in string format 6
Private and Confidential 1
Italc 1
Barcode 7
Count and display entries 8
Size limit for email signature 1
Hey Google where is my answer 5

Top