Function MEFDecApVirg(num As Double, dec As Byte, Optional ExactDec As Boolean, Optional sep As Boolean, Optional suf As String, Optional signe As Boolean = False) As String
'Renvoie la syntaxe de MEF
'Doit être couplé avec la fonction "HowLong"
'Magic_Doctor / mapomme / Hieu
'- num : le chiffre à traiter
'- dec : le nombre maximal de décimales après la virgule
'- ExactDec : uniquement si "True", complète, s'il le faut, par des "0" la fin de la chaîne
'- sep : uniquement si "True", séparateur des milliers
'- suf : un éventuel suffixe (%, mL...)
'- signe : uniquement si "True", précède le nombre saisi d'un "+" s'il est positif, d'un "-" s'il est négatif. En revanche rien s'il est omis
'Exemple : [A6].NumberFormat = MEFDecApVirg([A6], 2,,, " Romina", True) --> si [A6] = 223645,55358 => + 223.645,55 Romina
Dim x As Byte, WF, SepDec$, MEF As String, sm As String
num = CDbl(Round(num, dec))
x = HowLong(num)
'x = Len(num) - Len(Int(num)) - 1 'NE MARCHE PAS
Set WF = WorksheetFunction
SepDec = Application.International(xlDecimalSeparator): sm = IIf(sep = True, Chr(35) & SepDec & Chr(35) & Chr(35), "")
Application.Volatile
If x > dec Then
x = dec
ElseIf x = 0 Then
MEF = Chr(48)
Else
MEF = Chr(48) & IIf(dec = 0, "", Chr(46) & WF.Rept(Chr(48), x))
End If
If ExactDec = True Then
MEF = IIf(dec = 0, Chr(48), Chr(48) & Chr(46) & WF.Rept(Chr(48), dec))
End If
If Not IsMissing(suf) Then
MEF = MEF & Chr(34) & suf & Chr(34)
End If
MEF = sm & MEF
If signe = True Then
MEF = "[>0]+ " & MEF & ";[<0]- " & MEF
End If
MEFDecApVirg = MEF
End Function