Function FractionSeringue(num As Double, den As Integer) As String
'Fractionne des seringues
'eriiiic / Magic_Doctor
'- num = volume seringue (décimal. Il existe des seringues de 0,3 mL ou de 2,5 mL)
'- den = nombre de graduations de la seringue (toujours entier. Faut quand même pas déconner !!!)
'Ex : num = 2 (mL), den = 100 (graduations) --> 1/50ème de mL/Gr
Dim x As Byte, fraction As String, y As Byte, PosSlash As Byte, suf As String
x = HowLong(num) 'nombre de décimales après la virgule
If x > 0 Then
num = num * 10 ^ x
den = den * 10 ^ x
End If
fraction = Application.Text(num / den, "#?/???")
y = Len(fraction)
PosSlash = InStr(fraction, "/")
num = Left(fraction, PosSlash - 1)
den = Right(fraction, y - PosSlash)
If den = 1 Then fraction = num
If den = 1 Or den = 2 Then
suf = " mL/Gr"
ElseIf den = 3 Or den = 4 Then
suf = " de mL/Gr"
Else
suf = "ème de mL/Gr"
End If
FractionSeringue = Trim(fraction) & suf
End Function
--------------------------------------------------------------------------
Function HowLong(dNum As Double) As Byte
'Renvoie le nombre de chiffres après la virgule
Dim SepDec$, tmp, posDec
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