Calculation the numbers which more than 15 digits through VBA

Viewed 182

as far as I concern, it is permissible in VBA to do the calculation larger than 15 digits which giving you no zeroes automatically after the fifteenth digit -> more accuracy.

The idea is, the calculation could be done in VBA. The wished result(1,07007000700007000007654321) can be presented in excel as a string data type through format conversion(it is just to show in Excel sheet not to be calculated)

Question:

1 + 0.07007000700007000007654321

-> Excel gives 1.07007000700007000008

Expectation: 1.07007000700007000007654321

Here are my codes:

    Sub test()
    Dim y As Double
    Dim m As String

    'cell(1,1) is where 0.07007000700007000007654321
    y = 1 + Cells(1, 1)

    m = CStr(y)

    Cells(2, 1).Value = m

    End Sub

Thanks for the time and knowledge, guys!

1 Answers

Use Decimal - which needs a variable declared as Variant:

    Dim y As Variant
    Dim m As String

    'cell(1,1) is where 0.07007000700007000007654321
    y = 1 + CDec(Cells(1, 1))

    m = CStr(y)

    ' m -> "1.07007000700007000007654321"
Related