473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 3823
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 places, is this a limitation of 32-bit machines or...
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 value ? So that I will get decimal value 3446 ...
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 if PrincRepay is 78.20 it will display it as 78.2...
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 beyond the 2nd decimal place(###.##). I figured a...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
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 posting over some news servers. This is why I'm...
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 want output 5.00 like that. please help me. ...
3
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble ...
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 java.math.BigDecimal.<init>(BigDecimal.java:455) at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.