Bonjour a tous,
bon, comme je me suis arrache deux-trois cheveux pour faire une conversion qui marche bien...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 private string ArabicToRoman(int arabicNumber, bool isUpperCase) { string result = string.Empty; if (arabicNumber == 0) return result; try { if (arabicNumber >= 889) { result = ArabicToRomanHelper(arabicNumber - 1000, "M"); } else if (arabicNumber >= 389) { result = ArabicToRomanHelper(arabicNumber - 500, "D"); } else if (arabicNumber >= 89) { result = ArabicToRomanHelper(arabicNumber - 100, "C"); } else if (arabicNumber >= 39) { result = ArabicToRomanHelper(arabicNumber - 50, "L"); } else if (arabicNumber >= 9) { result = ArabicToRomanHelper(arabicNumber - 10, "X"); } else if (arabicNumber >= 4) { result = ArabicToRomanHelper(arabicNumber - 5, "V"); } else if (arabicNumber >= 1) { result = ArabicToRomanHelper(arabicNumber - 1, "I"); } else if (arabicNumber <= -889) { result = ArabicToRomanHelper(arabicNumber + 1000, "M"); } else if (arabicNumber <= -389) { result = ArabicToRomanHelper(arabicNumber + 500, "D"); } else if (arabicNumber <= -89) { result = ArabicToRomanHelper(arabicNumber + 100, "C"); } else if (arabicNumber <= -39) { result = ArabicToRomanHelper(arabicNumber + 50, "L"); } else if (arabicNumber <= -9) { result = ArabicToRomanHelper(arabicNumber + 10, "X"); } else if (arabicNumber <= -4) { result = ArabicToRomanHelper(arabicNumber + 5, "V"); } else if (arabicNumber <= -1) { result = ArabicToRomanHelper(arabicNumber + 1, "I"); } } catch (Exception e) { result = "Error : " + e.Message; } return isUpperCase ? result.ToUpper() : result.ToLower(); } private string ArabicToRomanHelper(int arabicNumber, string letter) { if (arabicNumber < 0) { return ArabicToRoman(arabicNumber, true) + letter; } return letter + ArabicToRoman(arabicNumber, true); }
et la meme en VB (tant qu'a faire...)
En esperant que ca serve a qqun
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Function ArabicToRoman(ByVal arabicNumber AS Integer, Optional ByVal isUpperCase As boolean = true) as string Dim result as string = string.Empty if arabicNumber = 0 Then return result try if arabicNumber >= 889 then result = ArabicToRomanHelper(arabicNumber - 1000, "M") else if arabicNumber >= 389 then result = ArabicToRomanHelper(arabicNumber - 500, "D") else if arabicNumber >= 89 then result = ArabicToRomanHelper(arabicNumber - 100, "C") else if arabicNumber >= 39 then result = ArabicToRomanHelper(arabicNumber - 50, "L") else if arabicNumber >= 9 then result = ArabicToRomanHelper(arabicNumber - 10, "X") else if arabicNumber >= 4 then result = ArabicToRomanHelper(arabicNumber - 5, "V") else if arabicNumber >= 1 then result = ArabicToRomanHelper(arabicNumber - 1, "I") else if arabicNumber <= -889 then result = ArabicToRomanHelper(arabicNumber + 1000, "M") else if arabicNumber <= -389 then result = ArabicToRomanHelper(arabicNumber + 500, "D") else if arabicNumber <= -89 then result = ArabicToRomanHelper(arabicNumber + 100, "C") else if arabicNumber <= -39 then result = ArabicToRomanHelper(arabicNumber + 50, "L") else if arabicNumber <= -9 then result = ArabicToRomanHelper(arabicNumber + 10, "X") else if arabicNumber <= -4 then result = ArabicToRomanHelper(arabicNumber + 5, "V") else if arabicNumber <= -1 then result = ArabicToRomanHelper(arabicNumber + 1, "I") end if catch e as Exception result = "Error : " & e.Message end try if isUpperCase then return result.ToUpper() else return result.ToLower() end if end function Function ArabicToRomanHelper(ByVal arabicNumber as Integer, Byval letter as String) as string if arabicNumber < 0 then return ArabicToRoman(arabicNumber, true) + letter else return letter + ArabicToRoman(arabicNumber, true) end if end function
Partager