Texte Nbzero

Magic_Doctor

XLDnaute Barbatruc
VB:
Function Nbzero(c As Range) As Byte
'***********************************************
'Renvoie le nombre de 0 juste après la virgule
'***********************************************
'Ex : 2,20075 --> 0
'     2,00054084 --> 3

    If Not IsNumeric(CStr(c)) Then Exit Function
    Dim x$, deb%, i%
    x = Format(c, "0." & String(999, "0"))
    deb = InStr(x, Application.DecimalSeparator) + 1
    For i = deb To Len(x)
        If Mid(x, i, 1) <> "0" Then Nbzero = i - deb: Exit Function
    Next
End Function
 
Dernière édition:

dysorthographie

XLDnaute Accro
bonjour,
VB:
Function Nbzero(c) As Integer
If Not IsNumeric(CStr(c)) Then Exit Function
Nbzero = Len(Split(Replace(c, ",", ".") & ".", ".")(1)) - Len(CStr(Val(Split(Replace(c, ",", ".") & ".", ".")(1))))
If Nbzero < 0 Then Nbzero = 0
End Function
Sub test()
Debug.Print Nbzero(1234.01),Nbzero(1234.001),Nbzero(1234.0001),Nbzero(1234.00001)
End Sub
 
Dernière édition:

Magic_Doctor

XLDnaute Barbatruc
Bonjour,

Je viens d'essayer votre fonction qui marche très bien.
Nettement plus concise et élégante que celle que j'avais proposée.
Adoptée !

PS : déclarer la fonction "%" n'est-ce pas exagéré ?
 

Discussions similaires

Statistiques des forums

Discussions
312 103
Messages
2 085 325
Membres
102 862
dernier inscrit
Emma35400