Round to the hundredeths place?

Dodgeram01

Active member
Joined
Apr 9, 2002
Messages
41
Location
Upstate NY
Okay, practicing my coding skills (lol), I decided to make a little program that would figure the sales tax in with stuff. Anyways, Ive come to the conclusion that itd be a lot more accurate if it would round the total amount to the hundredths place. I believe it will be somethign with the math.round(number) deal, but I cant quite figure it out. Thanks. (the number is assigned to a string).
 
You first need to convert the string into a number which you can
work with, and then you can use the Round function to get it
to a certain decimal place. Consider this example:

Code:
    Dim dNum As Double  Number before rounding
    Dim dNumRounded As Double  Number after rounding

    dNum = Double.Parse("14.52612")  Turn the String into a Double

    dNumRounded = Math.Round(dNum, 2)  Round it (the 2 is the # of decimal places to round)

    MessageBox.Show(dNumRounded.ToString)  Shows the results (should be "14.53")

HTH
 
Back
Top