Some math problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Evolution445
    New Member
    • Jul 2007
    • 63

    Some math problems

    Hi,

    Im making a small tool that helps gamers keep track of their kills and deaths, and their kill/death ratio.

    I calculate ratio on startup of the program, straight after kills and deaths are loaded off my website.

    Code:
    Dim ratio As Decimal
    
    ratio = Val(txt_kills.Text / txt_deaths.Text)
    At the moment, kills = 172 and deaths = 145. Ratio results in 1,1862068. How can I round this number up and turn this into a number with 2 integers after the dot? ( 1.19 )

    I tried a hundred things so far but I cannot figure this out.


    Any help appreciated. Thanks!
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Multiply your result by 100
    Move it into an int (which doesn't carry any decimal points)
    Then move it back into a float divided by 100

    Comment

    • Evolution445
      New Member
      • Jul 2007
      • 63

      #3
      I cannot use "ToFloat" and as type, my VB2005 doesnt recognise a Float either.
      Currently I have:

      Code:
              Dim ratio As Decimal
              Dim ratio2 As Int32
              Dim ratio3
              ratio = Val(txt_kills.Text / txt_deaths.Text) * 100
              ratio2 = Decimal.ToInt32(ratio)
              ratio3 = Val(ratio2 / 100)
      This results in 1,186207, this means its rounded up but still not what I want. How can I turn this into 1.19 properly ?

      Thanks in advance

      Comment

      • Evolution445
        New Member
        • Jul 2007
        • 63

        #4
        Fixed now, I had an error somewhere else, which meant during debug, VB2005 didnt show the latest changes I made in code. Thanks for help

        Comment

        Working...