Solved

Double to String, need precision

Posted on 2002-04-06
5
287 Views
Last Modified: 2010-05-02
Hi!
when I cast a Double to String, it keeps only the first 15 significative numbers.. is there a way to increase this limit?

thanks a lot
0
Comment
Question by:benhere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:sharmon
ID: 6923551
I believe VB follows the IEEE 754 specification strictly which is what is causing VB to only allow 15 digits of precision.  I have ran into this problem before but was unable to find a solution around it.

Regards,
Shannon
0
 
LVL 15

Accepted Solution

by:
ameba earned 200 total points
ID: 6923591
Instead of Double use some data type with better precision, e.g. Currency or Decimal:

Private Sub Form_Click()
    Dim x As Variant
    x = CDec(0) ' convert to Decimal
   
    x = CDec(1000000) / 333
    Print x

    Print CDbl(1000000) / 333
End Sub
0
 
LVL 2

Author Comment

by:benhere
ID: 6923952
ok, so lets say I want to write a function that converts a double to string

Public Function DoubleToString(pValue As Double) As String

???

End Function


Would this be possible to implement using CDec()? Or is it actually the Double that is limitted to 15 digits?
Because I tought the Double had a bid precision and that it was the convertion to String that was trimming numbers, is that true?

thanks
0
 
LVL 15

Expert Comment

by:ameba
ID: 6924002
The Double is limitted (to 64 bits); such function cannot give you more precission.
0
 
LVL 2

Author Comment

by:benhere
ID: 6924314
oh, ok then
thanks a lot
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSON Response and request in VB6 application 11 820
VB6 - Scroll Mouse wheel on Picturebox 13 97
Problem to line 23 74
transition to visual .net from vb6 5 63
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question