467,872 Members | 1,566 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,872 developers. It's quick & easy.

Convert double to string with more then 9 decimal places

Hello,

I would like to convert a double to a string and have the resulting string
contain all of the original values after the decimal place. Currently, the
problem that I am having is that the new string value is being rounded to
nine decimal places.

Dim dblX As Double = 146785.62713610753
dim strText as String = dblX.ToString()

strText results in the value of "146785.627136108". Using the
..ToString(N15) results in the same rounded string value.

Thanks,
Apr 13 '07 #1
  • viewed: 3585
Share:
3 Replies
Scott wrote:
Hello,

I would like to convert a double to a string and have the resulting string
contain all of the original values after the decimal place. Currently, the
problem that I am having is that the new string value is being rounded to
nine decimal places.

Dim dblX As Double = 146785.62713610753
dim strText as String = dblX.ToString()

strText results in the value of "146785.627136108". Using the
.ToString(N15) results in the same rounded string value.

Thanks,
That is not possible. The value does not contain more digits. The
literal value that you assign to the variable has more significant
digits than can be represented in a Double.

--
Göran Andersson
_____
http://www.guffa.com
Apr 13 '07 #2
Hello Goran,

Thanks you for the information. Is there any method to get the literal
value; I can view it in the VS while debugging.

Thanks,

"Göran Andersson" wrote:
Scott wrote:
Hello,

I would like to convert a double to a string and have the resulting string
contain all of the original values after the decimal place. Currently, the
problem that I am having is that the new string value is being rounded to
nine decimal places.

Dim dblX As Double = 146785.62713610753
dim strText as String = dblX.ToString()

strText results in the value of "146785.627136108". Using the
.ToString(N15) results in the same rounded string value.

Thanks,

That is not possible. The value does not contain more digits. The
literal value that you assign to the variable has more significant
digits than can be represented in a Double.

--
Göran Andersson
_____
http://www.guffa.com
Apr 13 '07 #3
Hi,

This issue is documented in the "Double.ToString Method" official link
below:
http://msdn2.microsoft.com/en-us/lib....tostring.aspx

"By default, the return value only contains 15 digits of precision although
a maximum of 17 digits is maintained internally. If the value of this
instance has greater than 15 digits, ToString returns
PositiveInfinitySymbol or NegativeInfinitySymbol instead of the expected
number. If you require more precision, specify format with the "G17" format
specification, which always returns 17 digits of precision, or "R", which
returns 15 digits if the number can be represented with that precision or
17 digits if the number can only be represented with maximum precision."

So, you should use "R" or "G17" format string, like this:
Dim dblX As Double = 146785.62713610753
Dim strText As String = dblX.ToString("G17")

This works well on my side. Furthermore, the link below contains the most
complete document for numeric type:
"Standard Numeric Format Strings"
http://msdn2.microsoft.com/en-us/library/dwhawy9k.aspx

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 16 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Eoin Mcloughlin | last post: by
3 posts views Thread by Gospill | last post: by
4 posts views Thread by STom | last post: by
3 posts views Thread by David | last post: by
1 post views Thread by AnandhaMurugan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.