473,791 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.62713610 753
dim strText as String = dblX.ToString()

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

Thanks,
Apr 13 '07 #1
3 3856
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.62713610 753
dim strText as String = dblX.ToString()

strText results in the value of "146785.6271361 08". 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.62713610 753
dim strText as String = dblX.ToString()

strText results in the value of "146785.6271361 08". 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.ToStrin g 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
PositiveInfinit ySymbol or NegativeInfinit ySymbol 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.62713610 753
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
3286
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 is it possible to use more decimal places? Has something already been written to do this? If not, what would one have to do enable it?
3
122081
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 Thanks.
4
78798
by: STom | last post by:
How do you convert a string in C# to decimal? STom
6
16650
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 PrincRepay, payment and IntAmt are double PrincRepay = Math.Round(payment - IntAmt,2); PrincRepayStr = PrincRepay.ToString("N2");
5
23955
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 Ctype to a decimal value would do that but the four decimal places remain. I found a truncate function but it only truncates to whole numbers. how can I do the truncation? Thanks, G
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly.
19
3614
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 starting a new one] I'd still like to finish this rounding mess. As a startup lemma we can take that VK is the worst programmer of all times and places: let's move from here forward please. The usability of any program depends on exact behavior...
1
2580
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. thanks in advance
3
1992
by: David | last post by:
Any ideas why this statement: mBalanceChange = Double.Parse(strCurrentBalance, Globalization.NumberStyles.AllowThousands Or Globalization.NumberStyles.AllowDecimalPoint) - mBalanceDouble would leave me with a double containing over 10 decimal places when strCurrentBalance was a string containing a double with two decimal places and mBalanceDouble contained only two decimal places to begin with?
1
3363
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 java.math.BigDecimal.<init>(BigDecimal.java:724) at org.openbravo.erpCommon.ad_reports.Hierarchical_trial_balance_report.printPagePDF(Hierarchical_trial_balance_report.java:550) at...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.