Dim lNombre As Long Dim lReste As Long Dim lCombien As Long Dim lDeFois As Long Dim r As Long Dim sResult As String lNombre = 124 sResult = "" lReste = lNombre For r = 9 To 0 Step -1 ' Maxi 9 chiffres dans ce nombre (limite du Long) lDeFois = 10 ^ r If lReste Mod (lDeFois) <> lReste Then lCombien = Fix(lReste / lDeFois) sResult = sResult & _ CStr(lCombien) & _ "*" & CStr(lDeFois) & _ " + " lReste = lReste - (lCombien * lDeFois) End If Next r If Right$(sResult, 3) " + " Then sResult Left$(sResult, Len(sResult) - 3) Debug.Print lNombre & " = " & sResult
Private Sub facteur10(valeur As Long) Dim fact As Long Dim iter As Long Dim expression As String expression = "" fact = 10 ^ (Len(Trim(str(valeur))) - 1) For iter = 0 To Len(Trim(str(valeur))) - 1 expression = expression & "( " & valeur \ fact & " * " & fact & " )" & " + " valeur = valeur Mod fact fact = fact / 10 Next iter expression = Mid(expression, 1, Len(expression) - 2) Me.Label1.Caption = expression End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub facteur10(valeur As Double) Dim fact As Double Dim iter As Long Dim operand As String Dim lengthnum As Byte Dim expression As String expression = "" 'calculate the number of digits of the whole part of valeur lengthnum = Len(Trim(str(Int(valeur)))) 'calculate the exponant the first digit is a multiple of 10^ exponant ' ex 124 = 1* 10^2 + 2*10^1 + 4*10^0 ' ex 124.56 = 1* 10^2 + 2*10^1 + 4*10^0 + 5*10^-1 + 6*10^-2 'get the first 10 ^exponant fact = 10 ^ (lengthnum - 1) For iter = 1 To Len(Trim(str(valeur))) 'get the digit operand = Mid(Trim(str(valeur)), iter, 1) If operand <> "." Then If operand <> "0" Then expression = expression & "( " & operand & " * " & fact & " ) " & " + " End If End If fact = fact / 10 Next iter Me.Label1.Caption = Mid(expression, 1, Len(expression) - 2) End Sub