473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. Dim ratio As Decimal
  2.  
  3. ratio = Val(txt_kills.Text / txt_deaths.Text)
  4.  
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!
Apr 4 '09 #1
3 1514
tlhintoq
3,525 Expert 2GB
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
Apr 4 '09 #2
I cannot use "ToFloat" and as type, my VB2005 doesnt recognise a Float either.
Currently I have:

Expand|Select|Wrap|Line Numbers
  1.         Dim ratio As Decimal
  2.         Dim ratio2 As Int32
  3.         Dim ratio3
  4.         ratio = Val(txt_kills.Text / txt_deaths.Text) * 100
  5.         ratio2 = Decimal.ToInt32(ratio)
  6.         ratio3 = Val(ratio2 / 100)
  7.  
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
Apr 5 '09 #3
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
Apr 5 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: R. Russell Kinter | last post by:
Hi all, First of all I am fairly new to javascript. Most of my experience has been with its subset vrmlscript, so have mercy. The following script works in I.E. 5.5, but hangs up in Netscape 4.8...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
30
by: nephish | last post by:
Hey there, i have tried about every graphing package for python i can get to work on my system. gnuplot, pychart, biggles, gdchart, etc.. (cant get matplot to work) so far, they all are working...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
110
by: Gregory Pietsch | last post by:
I'm writing a portable implementation of the C standard library for http://www.clc-wiki.net and I was wondering if someone could check the functions in math.h for sanity/portability/whatever. I'm...
10
by: David Coleman | last post by:
I am running VS 2003 and have applied SP1. (On WinXP SP2, .Net 1.1) In the Command Window I get the following ? Math.Round(0.715, 2) 0.72 ? Math.Round(0.725, 2) 0.72 ? Math.Round(0.735, 2)...
2
by: TurtleGuy910 | last post by:
I made a math game and wanted it to print out which questions you got right at the end. How do i do that? This is my code. # Welcome To The Math Game print "Welcome To The Math Game." print...
5
by: aguirre.adolfo | last post by:
Hi, I am a very newbie who would very much appreciate some hints. Python 2.52. on Windows XP for now. Soon on Ubuntu 8 I am teaching myself Python following free tutorials. I can solve...
5
by: Tzury Bar Yochay | last post by:
What is the reason math.pow yields OverflowError while python itself can calculate these large numbers. e.g: 1e+308 Traceback (most recent call last): File "<stdin>", line 1, in <module>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.