Dividing

TommyEvans

Active member
Joined
Feb 19, 2010
Messages
39
Programming Experience
Beginner
Alright. I have a code that is dividing the users input.

I need it to multiply as usual, but then round it to .xx .

THEN, I need it to grab the number after .xx. For instance, .xxxx.
I need it to make the third and fourth x (a number of course)
and output into a seperate label. It will show instead of a decimal, it will show xx%.

For example. User divides 9846 by 12580.

You get .782670906200318.

It will first display .78 in one label.

And then 26% in another label.

BUT (of course). If the output is above .99 percent (1.xx), then it will show 1.xx (or whatever) in the first label, and the same as above in the second.

Here is the code I've got so far. I've got no idea how to do the above.

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Kills As Integer
        Dim Deaths As Integer

        Kills = txtKills.Text
        Deaths = txtDeaths.Text
        lblOutput.Text = Kills / Deaths
    End Sub
 
Well, for the first part, I can't even it do either one. Only show the .xx or 1.xx etc. For the second part. I need it to grab the 3 and 4's decimal place, rounding the 4th.

Here is a better example.

1.23489

First label ONLY shows 1.23.

Second label, will show 49.

Do you get what I'm saying?
 
This should give you all you need:
VB.NET:
Dim number = 3.456789
Dim round2 = Math.Round(number, 2)
Dim round4 = Math.Round(number, 4)
Dim truncate2 = Math.Truncate(number * 100) / 100
Dim decimalPlaces3And4Rounded = CInt(round4 * 10000) Mod 100
Dim decimalPlaces3And4Truncated = CInt(Math.Truncate(number * 10000)) Mod 100

MessageBox.Show(round2.ToString())
MessageBox.Show(round4.ToString())
MessageBox.Show(truncate2.ToString())
MessageBox.Show(decimalPlaces3And4Rounded.ToString())
MessageBox.Show(decimalPlaces3And4Truncated.ToString())
 
Amazing! Now how would I go about letting the users input the numbers to divide by (txtKills and txtDeaths) and then displaying the number (1.xx) not rounded, and then the 1.11xx numbers, in labels (lblKD and lblPercent) ?
 
Back
Top