Forum Discussion

gdzanko's avatar
gdzanko
New Contributor
13 years ago

Rounding currency

I am new to SmartBear and need to round the decimal part of currency and am not sure how to do this in Visual Basic. If I use the round method it will round to the nearest whole number but that is not what I need. I need it to round just the decimal part of the number instead. For example 7.125 would need to be rounded to 7.13. How can I do this in Test Complete?
  • Anonymous's avatar
    Anonymous

    Hi Gina,



    Try using the following script to accomplish your task:



    //Use this function to round the decimal part of the number

    Function MathRound(X, I)

       MathRound = Int(X * 10 ^ I + 0.5) / 10 ^ I

    End Function





    Sub Main()

      Log.Message(MathRound(7.125, 2))

    End Sub





    Is this what you need?
  • VLapidus's avatar
    VLapidus
    Frequent Contributor
    Call the Round function with the second parameter that stand for the number of digits after the delimiter included in the rounding:



    Call Round(7.125, 2)
  • Anonymous's avatar
    Anonymous

    Hi Gina,



    Does Ncoes's suggestion help you?

    For additional information about this function, please refer to the Round Function MSDN article.
  • gdzanko's avatar
    gdzanko
    New Contributor
    The Round function uses the round to even concept and I need the round to larger concept.

    Rule One If the rounding digit is 4, 3, 2, or 1, drop all digits to the right of it.


    Rule Two If the rounding digit is 5, 6, 7, 8, or 9 add one to the rounding digit and drop all digits to the right of it.



    Is there a function in SmartBear to handle this requirement?