Code : Tout sélectionner
Procedure.s nb2txt(Number)
num.s=Str(number)
Dim nb.s(100)
nb(1)="un"
nb(2)="deux"
nb(3)="trois"
nb(4)="quatre"
nb(5)="cinq"
nb(6)="six"
nb(7)="sept"
nb(8)="huit"
nb(9)="neuf"
nb(10)="dix"
nb(11)="onze"
nb(12)="douze"
nb(13)="treize"
nb(14)="quatorze"
nb(15)="quinze"
nb(16)="seize"
nb(17)="dix-sept"
nb(18)="dix-huit"
nb(19)="dix-neuf"
nb(20)="vingt"
nb(30)="trente"
nb(40)="quarante"
nb(50)="cinquante"
nb(60)="soixante"
nb(70)="soixante-dix"
nb(80)="quatre-vingt"
nb(90)="quatre-vingt-dix"
nb(28)="cent"
nb(29)="cents"
nb(31)="mille"
nb(32)="million"
nb(33)="millions"
nb(34)="milliard"
nb(35)="milliards"
If Len(num)=3
If Val(Left(num,1))>1 And Val(Right(num,2))=0
numb.s=nb(Val(Left(num,1)))+" "+nb(29)
ElseIf Val(Left(num,1))>1 And Val(Right(num,2))<>0
numb.s=nb(Val(Left(num,1)))+" "+nb(28)
Else
numb=nb(28)
EndIf
If Val(Right(num,2))>10 And Val(Right(num,2))<20
numb=numb+" "+nb(Val(Right(num,2)))
ElseIf Val(Right(num,2))>70 And Val(Right(num,2))<80
If Val(Right(num,2))=71
numb=numb+" "+nb(60)+"-et-"+nb(10+Val(Right(num,1)))
Else
numb=numb+" "+nb(60)+"-"+nb(10+Val(Right(num,1)))
EndIf
ElseIf Val(Right(num,2))>90 And Val(Right(num,2))<100
numb=numb+" "+nb(80)+"-"+nb(10+Val(Right(num,1)))
ElseIf Val(Right(num,2))=21 Or Val(Right(num,2))=31 Or Val(Right(num,2))=41 Or Val(Right(num,2))=51 Or Val(Right(num,2))=61
numb=numb+" "+nb(10*Val(Mid(num,2,1)))+"-et-"+nb(Val(Right(num,1)))
Else
If Val(Mid(num,2,1))<>0
numb=numb+" "+nb(Val(Mid(num,2,1))*10)
b=1
EndIf
If Val(Right(num,1))<>0
If b=1 : int.s="-" : Else : int.s=" " : EndIf
numb=numb+int+nb(Val(Right(num,1)))
EndIf
EndIf
ElseIf Len(num)=2
If Val(num)>10 And Val(num)<20
numb=nb(Val(num))
ElseIf Val(num)>70 And Val(num)<80
If Val(num)=71
numb=nb(60)+"-et-"+nb(10+Val(Right(num,1)))
Else
numb=nb(60)+"-"+nb(10+Val(Right(num,1)))
EndIf
ElseIf Val(num)>90 And Val(num)<100
numb=nb(80)+"-"+nb(10+Val(Right(num,1)))
ElseIf Val(num)=21 Or Val(num)=31 Or Val(num)=41 Or Val(num)=51 Or Val(num)=61
numb=nb(10*Val(Left(num,1)))+"-et-"+nb(Val(Right(num,1)))
Else
If Val(Left(num,1))<>0
numb=nb(Val(Left(num,1))*10)
b=1
EndIf
If Val(Right(num,1))<>0
If b=1 : int.s="-" : Else : int.s=" " : EndIf
numb=numb+int+nb(Val(Right(num,1)))
EndIf
EndIf
Else
If Val(Right(num,1))<>0
numb=nb(Val(Right(num,1)))
EndIf
EndIf
ProcedureReturn numb
EndProcedure
Procedure.s NbToTxt(Number.l) ; Retourne sous forme texte le nombre choisie entre -2147483648 et +2147483647
If number<0
num.s="moins"
number=Abs(number)
Else
num.s=""
EndIf
lon=Len(Str(number))
If number=0
ProcedureReturn "zéro"
EndIf
If lon<4
num.s=num+nb2txt(number)
ElseIf lon>3 And lon<7
If Val(Right(Str(number),3))=0
num.s=num+nb2txt(Val(Left(Str(number),lon-3)))+" "+nb(31)
Else
num.s=num+nb2txt(Val(Left(Str(number),lon-3)))+" "+nb(31)+" "+nb2txt(Val(Right(Str(number),3)))
EndIf
ElseIf lon>6 And lon<10
If Val(Left(Str(number),lon-6))>1
num.s=num+nb2txt(Val(Left(Str(number),lon-6)))+" "+nb(33)
Else
num.s=num+nb2txt(Val(Left(Str(number),lon-6)))+" "+nb(32)
EndIf
If Val(Right(Str(number),6))>0
num.s=num.s+" "+NbToTxt(Val(Right(Str(number),6)))
EndIf
ElseIf lon>9 And lon<13
If Val(Left(Str(number),lon-9))>1
num.s=num+nb2txt(Val(Left(Str(number),lon-9)))+" "+nb(35)
Else
num.s=num+nb2txt(Val(Left(Str(number),lon-9)))+" "+nb(34)
EndIf
If Val(Right(Str(number),9))>0
num.s=num.s+" "+NbToTxt(Val(Right(Str(number),9)))
EndIf
EndIf
ProcedureReturn num
EndProcedure
Procedure IsInteger(Number.f) ; Retourne 1 si le nombre est entier
If Round(number, 1) = number And Round(number, 0) = number
ProcedureReturn 1
EndIf
EndProcedure
Procedure IsOddNumber(Number.l) ; Retourne 1 si le nombre est impair
If Round(number / 2, 1) <> number / 2 And Round(number / 2, 0) <> number / 2
ProcedureReturn 1
EndIf
EndProcedure
Procedure IsPrimaryNumber(Number.l) ; Retourne 1 si le nombre est premier
; algorithme de Knuth
Global list
If list = 0 : NewList listNP() : list = 1 : Else : ClearList(listNP()) : EndIf
AddElement(listNP()) : listNP() = 2
If IsOddNumber(number)
If number > 2
For a = 3 To Int(Round(Sqr(number), 1)) Step 2
v = 0
nbl = CountList(listNP())
For b = 0 To nbl - 1
SelectElement(listNP(), b)
If IsInteger(a / listNP()) = 0
v = v + 1
EndIf
Next
If v = nbl
AddElement(listNP())
listNP() = a
EndIf
Next
ElseIf number<2
ProcedureReturn 0
EndIf
v = 0
For a = 0 To CountList(listNP()) - 1
SelectElement(listNP(), a)
If IsInteger(number / listNP())
v = 1
EndIf
Next
If v = 0
ProcedureReturn 1
EndIf
Else
If number = 2
ProcedureReturn 1
EndIf
EndIf
EndProcedure