# How to convert european(eu) odds to united kingdom(uk) odds ?

March 12, 2013

A bit hard this one , but there is a way to convert EU odds to UK odds in php.

```function eu_to_uk_odds(\$odds){
if(floor(\$odds) !== \$odds){
\$odds = (string) round(\$odds - 1,2);
\$oddsArr = explode('.',\$odds);
\$f1 = (int) \$oddsArr[0].''.\$oddsArr[1];
\$minDel = \$this->gcd(\$f1,\$f2);
\$odds = \$f1 / \$minDel .'/'.\$f2/\$minDel;
} else {
\$odds = (\$odds-1).'/1';
}
return \$odds;
}

function gcd(\$a, \$b)
{
if (\$a == 0 || \$b == 0)
return abs( max(abs(\$a), abs(\$b)) );

\$r = \$a % \$b;
return (\$r != 0) ?
\$this->gcd(\$b, \$r) :
abs(\$b);
}

echo eu_to_uk_odds(2.3);
//13/100
echo eu_to_uk_odds(1.2);
//1/5

```

Simple as that.

tags:
posted in how to ?, php by Ivan Gospodinow

Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /home/c2kblate/sites/ivangospodinow.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048