Magic_Doctor
XLDnaute Barbatruc
Rebonjour,
Je voudrais connaître, pour des chiffres décimaux, le nombre de 0 (zéro(s)) qu'il y a immédiatement après la virgule.
Par exemple :
123,0258 ---> 1
5,00088 ---> 3
-0,000009036 ---> 5
J'avais conservé sous le coude ces 2 fonctions :
------------------------------------------------------------------------------------
Function HowLong(dNum As Double) As Byte
'Renvoie le nombre réel de chiffres après la virgule d'une nombre
Dim SepDec$, tmp$, posDec As Byte
On Error Resume Next
SepDec = Application.International(xlDecimalSeparator)
tmp = CStr(dNum)
posDec = InStr(tmp, SepDec)
If posDec = 0 Then
HowLong = 0
Else
HowLong = Len(tmp) - Len(Right(tmp, posDec))
End If
End Function
------------------------------------------------------------------------------------
Function ApresLaVirgule(cell As Range) As Byte
Dim SepDec$, tmp$, pos As Byte, res
On Error Resume Next
SepDec = Application.International(xlDecimalSeparator)
tmp = cell.Text
pos = InStr(1, tmp, SepDec)
If pos = 0 Then
res = 0
Else
res = Left(Right(tmp, Len(tmp) - pos), 8)
End If
If Len(res) = 1 Then res = res * 10
ApresLaVirgule = Len(res * 1)
End Function
------------------------------------------------------------------------------------
En soustrayant ces 2 fonctions (je sens que certains vont rigoler au vu de cet infâme bricolage...) :
HowLong([K17]) - ApresLaVirgule([K17])
J'obtiens bien le résultat attendu, mais ça plante avec les nombres entiers. ¡Caramba!
Un grand merci pour m'aider à sortir du ¡Caramba!
Je voudrais connaître, pour des chiffres décimaux, le nombre de 0 (zéro(s)) qu'il y a immédiatement après la virgule.
Par exemple :
123,0258 ---> 1
5,00088 ---> 3
-0,000009036 ---> 5
J'avais conservé sous le coude ces 2 fonctions :
------------------------------------------------------------------------------------
Function HowLong(dNum As Double) As Byte
'Renvoie le nombre réel de chiffres après la virgule d'une nombre
Dim SepDec$, tmp$, posDec As Byte
On Error Resume Next
SepDec = Application.International(xlDecimalSeparator)
tmp = CStr(dNum)
posDec = InStr(tmp, SepDec)
If posDec = 0 Then
HowLong = 0
Else
HowLong = Len(tmp) - Len(Right(tmp, posDec))
End If
End Function
------------------------------------------------------------------------------------
Function ApresLaVirgule(cell As Range) As Byte
Dim SepDec$, tmp$, pos As Byte, res
On Error Resume Next
SepDec = Application.International(xlDecimalSeparator)
tmp = cell.Text
pos = InStr(1, tmp, SepDec)
If pos = 0 Then
res = 0
Else
res = Left(Right(tmp, Len(tmp) - pos), 8)
End If
If Len(res) = 1 Then res = res * 10
ApresLaVirgule = Len(res * 1)
End Function
------------------------------------------------------------------------------------
En soustrayant ces 2 fonctions (je sens que certains vont rigoler au vu de cet infâme bricolage...) :
HowLong([K17]) - ApresLaVirgule([K17])
J'obtiens bien le résultat attendu, mais ça plante avec les nombres entiers. ¡Caramba!
Un grand merci pour m'aider à sortir du ¡Caramba!