Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Okay, practicing my coding skills (lol), I decided to make a little program that would figure the sales tax in with stuff. Anyways, I've come to the conclusion that it'd 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 can't quite figure it out. Thanks. (the number is assigned to a string).

Dodge

Grab Life By The Horns

  • *Experts*
Posted

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:

 

   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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...