• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

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
0
benhere
Asked:
benhere
  • 2
  • 2
1 Solution
 
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
 
amebaCommented:
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
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now