Solved

Double to String, need precision

Posted on 2002-04-06
5
284 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
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:sharmon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The Double is limitted (to 64 bits); such function cannot give you more precission.
0
 
LVL 2

Author Comment

by:benhere
Comment Utility
oh, ok then
thanks a lot
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now