Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Double to String, need precision

Posted on 2002-04-06
Medium Priority
290 Views
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
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
• 2
• 2

LVL 6

Expert Comment

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

ameba earned 800 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

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

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

LVL 2

Author Comment

ID: 6924314
oh, ok then
thanks a lot
0

## Featured Post

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month11 days, 1 hour left to enroll