finding the ratio bewteen 2 numbers

Associate
Joined
15 Sep 2007
Posts
48
does anyone know how to find the ratio between numbers in vb.net?

i am trying to work out what the odds are on a betting, say for example, i was was to recieve a pot of 5 for a bet of 2. That would be 5/2 or 2.5/1.
 
It is that easy.
It is, but it shouldn't be! Far too much processing power wasted on modern computers.

How about this instead:
Code:
    private const double P = 0.000000000000001;

    public double GetRatio(double a, double b)
    {
        return GetRatio(a, b, 1, 1);
    }

    private double GetRatio(double a, double b, double c, double d)
    {
        if (b * c < a)
            while (b * c < a)
                c += d;
        else if (b * c > a)
            while (b * c > a)
                c -= d;

        return (b * c == a || d < P) ? c : GetRatio(a, b, c, d / 10);
    }
You'll have to convert it to VB.NET yourself ;)


Mick.
 
Perhaps you caould turn it into a webservice? That would be, like, totally awesome.
Yes, I could also run a Web 2.14 (I upgraded) AJAX Enabled website to provide users with a fast access method of getting ratios rather than having to rely on their other systems.

I'll get the server ordered and look into the best ways of advertising the new service we're offering.


Mick.
 
Also consider that to win a pot of 5 for a bet of 2, the actual odds would be 3/2.

You win 5, but make a profit of 3
 
Yes, I could also run a Web 2.14 (I upgraded) AJAX Enabled website to provide users with a fast access method of getting ratios rather than having to rely on their other systems.

I'll get the server ordered and look into the best ways of advertising the new service we're offering.


Mick.

Outstanding. Ill see if I could run up some venture capital.

If only it was 1999, I reckon we could get a couple of million quid for this - as long as we had a flashy domain name.

www.ratio-tron.com?
 
I don't mean to **** on this otherwise hilarious thread, but I think the op would like something akin to:
Code:
$a = 5;
$b = 10;

ratio($a, $b); // 1:2
 
In that case:

Code:
Function GetRatio(ByVal a As Integer, ByVal b As Integer) As String
	Dim hcf As Integer = 1
	For i As Integer = hcf To Math.Min(a, b)
		If a Mod i = 0 And b Mod i = 0 Then
			hcf = i
		End If
	Next

	Return String.Format("{0}:{1}", a / hcf, b / hcf)
End Function

*runs off to wash hands after having written VB*
 
Last edited:
Back
Top Bottom