472,338 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,338 software developers and data experts.

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
3 3772
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Eoin Mcloughlin | last post by:
I have a perl script for calculating sequences that use numbers like 1/5908979186 however, I need to get more accuracy than the usual 15 decimal...
3
by: Gospill | last post by:
Hi Guru, If I have string like "0D76" for example, it is actually a 0x0D76 in hex format. How can I convert the hex string 0D76 into decimal...
4
by: STom | last post by:
How do you convert a string in C# to decimal? STom
6
by: Bill | last post by:
Hi I am having trouble trying to format a number string to two decimal places if the number ends in a 0 It formats fine otherwise. For example...
5
by: GaryB | last post by:
I have a database field that is the product of a multiply in a sql statement and it sometimes has 5 or more decimal places. I want to truncate...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for...
1
by: jesmi | last post by:
hi!! i want to place two fix decimal places after a digit even if there is no decimal places after a digit. for example if there is a number 5, i...
3
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or...
1
by: AnandhaMurugan | last post by:
I got a numberformatException when i convert from string to decimal how to resolve it java.lang.NumberFormatException at...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.