Double to String, need precision

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
LVL 2
benhereAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
amebaConnect With a Mentor Commented:
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
 
sharmonCommented:
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
 
benhereAuthor Commented:
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
 
amebaCommented:
The Double is limitted (to 64 bits); such function cannot give you more precission.
0
 
benhereAuthor Commented:
oh, ok then
thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.