Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD
PHP & SGBD Forum d'entraide sur les SGBD avec PHP. Avant de poster : FAQ BDD, toutes les FAQ PHP, cours BDD et sources BDD
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
Vieux 17/02/2010, 15h57   #1
Invité régulier
 
Inscription : novembre 2002
Messages : 50
Détails du profil
Informations forums :
Inscription : novembre 2002
Messages : 50
Points : 9
Points : 9
Par défaut Conversion de chiffre

Bonjour,

Je crée un site de paris gratuit qui est traduit en plusieurs langues.

Actuellement mon site affiche les cotes en décimales soit exemple

équipe x contre équipe y les cotes sont les suivantes

Cote 1 : 1.65
Cote 2 : 3.40
Cote 4 : 5.00

Je voulais savoir si il existait une fonction qui me permettent de les convertir en fractionnelles ce qui donnerait :

Cote 1 : 13/20
Cote 2 : 12/5
Cote 4 : 4/1

J'aimerai aussi les convertir au format US ce qui donnerait :

Cote 1 : -154
Cote 2 : +240
Cote 4 : +400

Merci d'avance.
nandofive est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/02/2010, 16h00   #2
Membre Expert
 
Avatar de Madfrix
 
Inscription : juin 2007
Messages : 2 248
Détails du profil
Informations personnelles :
Localisation : France, Gironde (Aquitaine)

Informations forums :
Inscription : juin 2007
Messages : 2 248
Points : 2 291
Points : 2 291
Salut, tu peux toujours utiliser cette classe ICI
Madfrix est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/03/2010, 15h40   #3
Invité régulier
 
Inscription : novembre 2002
Messages : 50
Détails du profil
Informations forums :
Inscription : novembre 2002
Messages : 50
Points : 9
Points : 9
Je viens de trouver ce que je recherchais pour la conversion :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
function isNum(args)
{
args = args.toString();
 
if (args.length == 0)
return false;
 
for (var i = 0;  i<args.length;  i++)
{
	if ((args.substring(i,i+1) < "0" || args.substring(i, i+1) > "9") && args.substring(i, i+1) != ".")
		{
		return false;
		}
}
 
return true;
 
}
 
 
function change(varr)
{
var aa = varr.value;
 
	if(isNum(aa))
	{
 
	}
	else
	{
		aa = aa.substring(0,aa.length-1);
		document.first.frac.value = aa;
	}
}
 
function hcfof(num1,num2)
{
	var firnum,secnum; 
	if(num1<num2)
	{
	 firnum = num1;
	 secnum = num2;
	}
	else
	{
	 firnum = num2;
	 secnum = num1;
	}
 
	var rem = (secnum%firnum);
 
	while(rem > 0)
	{
		secnum = firnum;
		firnum = rem;
		rem = (secnum%firnum);
	}
 
	var hcf = firnum;
 
	return hcf;
}
 
 
function calfrac()
{
var aa = document.first.frac.value;
 
	if(isNum(aa))
	{
	 aa=aa*1;
  	 var bb = Math.floor(aa);
	 var cc = aa-bb;
 
	 var dd = 1;	
	 if(cc != 0)
	 	dd = Math.pow(10,aa.toString().length-2);
	 var ee = Math.round(aa*dd);
 
	 document.first.t1.value = ee;
	 document.first.t2.value = dd;
 
	 var hcf = hcfof(ee,dd);
  	 ee = ee/hcf;
	 dd = dd/hcf;
 
	 document.first.t3.value = ee;
	 document.first.t4.value = dd;
	}
	else{}
}
 
 
function color(test)
{
 
	for(var j=2; j<6; j++)
	{
		var myI=document.getElementsByTagName("input").item(j);
		myI.style.backgroundColor=test;
 
	}
}
 
 
function color1(test)
{
var myI=document.getElementsByTagName("table").item(0);
//myI.setAttribute("style",ch);
myI.style.backgroundColor=test;
}
</script>
 
<body>
<table width=90% border=0 cellpadding=0 cellspacing=0 class=cbor>
<tr><td align=center class=chead>
		Fractional Calculator
</td></tr>
<tr><td class=content>
	<table width=100% align=center>
	<tr align=left width=100%><td colspan=2><b>Fractional Calculation</b></td></tr>
	<tr><td width=60%>
 
		<form name=first>
		<table align=center width=70%><tr><td colspan=2>
		Insert <b>Decimal Fraction</b> Value </td></tr>
		<tr><td colspan=2><input name=frac type="text" class='innerc resform' onkeyup="change(this)"  size=10> 
		<input type=button value=go onclick="calfrac()"> [example: 0.2345 ]
		<br><br><br></td></tr>
		<tr><td colspan=2><b>Result </b>- vulgar fractions</td><tr>
 
		<tr><td align=right>= <input name=t1 type="text"  readonly class=bac size=10>
		<span class=slash>/</span>
		</td><td align=left><br>
		<input name=t2 type="text"  readonly class=bac1 size=10><br><br></td></tr>
		<tr><td align=right>= <input name=t3 type="text"  readonly class=bac size=10>
		<span class=slash>/</span>
		</td><td align=left><br>
 
		<input name=t4 type="text"  readonly class=bac1 size=10></td></tr>
		</table>
	</form>
	</td></tr>
	</table>
    </td></tr>
</table>
Le problème de ce code est qu'il m'affiche m'a fraction dans deux input.

Est-il possible d'afficher les fraction dans un seul et même input ?
nandofive est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 13/03/2010, 17h08   #4
Invité régulier
 
Inscription : novembre 2002
Messages : 50
Détails du profil
Informations forums :
Inscription : novembre 2002
Messages : 50
Points : 9
Points : 9
C'est bon j'ai trouvé :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
<script language="javascript">
function isNum(args)
{
args = args.toString();
 
if (args.length == 0)
return false;
 
for (var i = 0;  i<args.length;  i++)
{
	if ((args.substring(i,i+1) < "0" || args.substring(i, i+1) > "9") && args.substring(i, i+1) != ".")
		{
		return false;
		}
}
 
return true;
 
}
 
 
function change(varr)
{
var aa = varr.value;
 
	if(isNum(aa))
	{
 
	}
	else
	{
		aa = aa.substring(0,aa.length-1);
		document.first.frac.value = aa;
	}
}
 
function hcfof(num1,num2)
{
	var firnum,secnum; 
	if(num1<num2)
	{
	 firnum = num1;
	 secnum = num2;
	}
	else
	{
	 firnum = num2;
	 secnum = num1;
	}
 
	var rem = (secnum%firnum);
 
	while(rem > 0)
	{
		secnum = firnum;
		firnum = rem;
		rem = (secnum%firnum);
	}
 
	var hcf = firnum;
 
	return hcf;
}
 
 
function calfrac()
{
var aa = document.first.frac.value;
 
	if(isNum(aa))
	{
	 aa=aa*1;
  	 var bb = Math.floor(aa);
	 var cc = aa-bb;
 
	 var dd = 1;	
	 if(cc != 0)
	 	dd = Math.pow(10,aa.toString().length-2);
	 var ee = Math.round(aa*dd);
 
	 document.first.t1.value = ee;
	 document.first.t2.value = dd;
 
	 var hcf = hcfof(ee,dd);
  	 ee = ee/hcf;
	 dd = dd/hcf;
	 seltext = ee+"/"+dd;
	 document.first.t3.value = ee;
	 document.first.t4.value = seltext;
	}
	else{}
}
 
 
function color(test)
{
 
	for(var j=2; j<6; j++)
	{
		var myI=document.getElementsByTagName("input").item(j);
		myI.style.backgroundColor=test;
 
	}
}
 
 
function color1(test)
{
var myI=document.getElementsByTagName("table").item(0);
//myI.setAttribute("style",ch);
myI.style.backgroundColor=test;
}
</script>
 
<body>
<table width=90% border=0 cellpadding=0 cellspacing=0 class=cbor>
<tr><td align=center class=chead>
		Fractional Calculator
</td></tr>
<tr><td class=content>
	<table width=100% align=center>
	<tr align=left width=100%><td colspan=2><b>Fractional Calculation</b></td></tr>
	<tr><td width=60%>
 
		<form name=first>
		<table align=center width=70%><tr><td colspan=2>
		Insert <b>Decimal Fraction</b> Value </td></tr>
		<tr><td colspan=2><input name=frac type="text" class='innerc resform' onkeyup="change(this)"  size=10 > 
		<input type=button value=go onclick="calfrac()"> [example: 0.2345 ]
		<br><br><br></td></tr>
		<tr><td colspan=2><b>Result </b>- vulgar fractions</td><tr>
 
		<tr><td align=right>= <input name=t1 type="text"  readonly class=bac size=10>
		<span class=slash>/</span>
		</td><td align=left><br>
		<input name=t2 type="text"  readonly class=bac1 size=10><br><br></td></tr>
		<tr><td align=right>= <input name=t3 type="text"  readonly class=bac size=10>
		<span class=slash>/</span>
		</td><td align=left><br>
 
		<input name=t4 type="text"  readonly class=bac1 size=10></td></tr>
        <label name=ta></label>
		</table>
	</form>
	</td></tr>
	</table>
    </td></tr>
</table>
Il me reste plus que les conversion au format US
nandofive est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +1. Il est actuellement 03h36.


 
 
 
 
Partenaires

Hébergement Web