2 Replies - 2030 Views - Last Post: 02 September 2012 - 04:02 AM Rate Topic: -----

#1 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Rounding off Decimals

Posted 02 September 2012 - 02:49 AM

Hey!
Okay so here's my program design: http://puu.sh/11gFY
And here is the code for the math that is to be rounded:
    Private Sub EnterBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnterBtn.Click
        FlightTimeResultLbl.Text = (2 * VelocityBox.Text * 0.7071067812) / 9.8
        DistanceResultLbl.Text = VelocityBox.Text * FlightTimeResultLbl.Text * 0.7071067812
    End Sub



Basically. The user enters the velocity and the code calculates the distance and flight time.
I need it rounded to 2 decimal places. Im not sure.
I looked up Math.round but i wasn't sure where to place it or how to round it off? :/

Many thanks <3

Is This A Good Question/Topic? 0
  • +

Replies To: Rounding off Decimals

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,755
  • Joined: 26-March 09

Re: Rounding off Decimals

Posted 02 September 2012 - 03:56 AM

You'd be better asking a mod to move this to the VB.Net forum, as it's not VB6 code, that way, you'll likely get a better answer to you question.

Using the math.round function, should be a case of calculating your value into a Double datatype, then calling the round function, so something like.

double dblMyResult
'Replace the fixed number with your calculation
dblMyResult = 123.456789

' You give math.round, your value and the number of decimal places.
txtResult.Text = math.round(dblMyResult, 2)


Was This Post Helpful? 0
  • +
  • -

#3 Rmclayton  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 20-June 12

Re: Rounding off Decimals

Posted 02 September 2012 - 04:02 AM

That works! Thank you! <3
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1