7 réponses
Three other solutions (but they work):
Put 3 buttons on the frame:
Private Sub Command_Click()
Dim nb As Double
Dim a1 As String
Dim dec_nb As String
Dim ent_nb As String
nb = 42653.6207986111
a1 = CStr(nb)
dec_nb = CDbl(Right(a1, Len(a1) - InStr(1, a1, ",")))
MsgBox dec_nb ' = "6207986111"
ent_nb = CDbl(Left(a1, Len(a1) - (Len(a1) - InStr(1, a1, ",") + 1)))
MsgBox ent_nb ' = 42653
End Sub
Or (Universal to respond to rindher)
Private Sub Command1_Click()
Dim nb As Double
Dim a As String
Dim dec_nb As String
Dim ent_nb As String
nb = 42653.6207986111
a = CStr(nb)
dec_nb = Right(a, Len(a) - Len(CStr(Int(a))) - 1)
MsgBox dec_nb ' = "6207986111"
ent_nb = Left(a, Len(a) - Len(dec_nb) - 1)
MsgBox ent_nb ' = 42653
End Sub
Or to do scientific and universal (different results!):
Private Sub Command2_Click()
Dim nb As Double
Dim a As String
Dim dec_nb As Double
Dim ent_nb_s As String
Dim ent_nb As Double
nb = 42653.6207986111
ent_nb = Int(nb)
MsgBox ent_nb ' = 42653
ent_nb_s = nb - Int(nb)
dec_nb = ent_nb_s * 10 ^ (Len(ent_nb_s) - 2)
MsgBox dec_nb ' = 620798611096689
End Sub
Put 3 buttons on the frame:
Private Sub Command_Click()
Dim nb As Double
Dim a1 As String
Dim dec_nb As String
Dim ent_nb As String
nb = 42653.6207986111
a1 = CStr(nb)
dec_nb = CDbl(Right(a1, Len(a1) - InStr(1, a1, ",")))
MsgBox dec_nb ' = "6207986111"
ent_nb = CDbl(Left(a1, Len(a1) - (Len(a1) - InStr(1, a1, ",") + 1)))
MsgBox ent_nb ' = 42653
End Sub
Or (Universal to respond to rindher)
Private Sub Command1_Click()
Dim nb As Double
Dim a As String
Dim dec_nb As String
Dim ent_nb As String
nb = 42653.6207986111
a = CStr(nb)
dec_nb = Right(a, Len(a) - Len(CStr(Int(a))) - 1)
MsgBox dec_nb ' = "6207986111"
ent_nb = Left(a, Len(a) - Len(dec_nb) - 1)
MsgBox ent_nb ' = 42653
End Sub
Or to do scientific and universal (different results!):
Private Sub Command2_Click()
Dim nb As Double
Dim a As String
Dim dec_nb As Double
Dim ent_nb_s As String
Dim ent_nb As Double
nb = 42653.6207986111
ent_nb = Int(nb)
MsgBox ent_nb ' = 42653
ent_nb_s = nb - Int(nb)
dec_nb = ent_nb_s * 10 ^ (Len(ent_nb_s) - 2)
MsgBox dec_nb ' = 620798611096689
End Sub
R = A / B
Pos = InStr(1, R, ",") ' searching for the existence of the comma in R
If Pos <> 0 Then ' if the comma exists
E= CInt(Left(R, Pos - 1)) ' then retrieve the digits before the comma (integer part)
Tai1 = Len(R) - (Pos + 1) ' calculating the length after the comma
D = CInt(Right(R, Tai1)) ' retrieve the digits after the comma (decimal part)
End If
Pos = InStr(1, R, ",") ' searching for the existence of the comma in R
If Pos <> 0 Then ' if the comma exists
E= CInt(Left(R, Pos - 1)) ' then retrieve the digits before the comma (integer part)
Tai1 = Len(R) - (Pos + 1) ' calculating the length after the comma
D = CInt(Right(R, Tai1)) ' retrieve the digits after the comma (decimal part)
End If
Furthermore, it's really foolish as a method because the proper functioning of the function depends on the regional settings of the PC... On an American PC, for example, the separator is the "."...
Afterwards, it might be the least intelligent way to achieve this kind of result: going through a conversion to a string then to a number... Luckily, current processors are fast, but just trying to perform this operation 1,000,000 times makes you realize how slow and burdensome it is for the PC...
Try to provide some code that is a bit serious...
Afterwards, it might be the least intelligent way to achieve this kind of result: going through a conversion to a string then to a number... Luckily, current processors are fast, but just trying to perform this operation 1,000,000 times makes you realize how slow and burdensome it is for the PC...
Try to provide some code that is a bit serious...
Private Function IntDec(ByVal strch As String, ByVal valeur() As Integer) As Integer()
Dim Pos As Integer = InStr(strch, ".") ' search for the existence of the point in R
If Pos <> 0 Then ' if the point exists
valeur(0) = CInt(Int(strch)) ' then retrieve the digits before the point (integer part)
valeur(1) = CInt(CStr(strch).Substring(Pos, 2)) ' retrieve the digits after the point (decimal part)
Else
valeur(0) = CInt(Int(strch))
valeur(1) = 0
End If
Return valeur
End Function
Dim Pos As Integer = InStr(strch, ".") ' search for the existence of the point in R
If Pos <> 0 Then ' if the point exists
valeur(0) = CInt(Int(strch)) ' then retrieve the digits before the point (integer part)
valeur(1) = CInt(CStr(strch).Substring(Pos, 2)) ' retrieve the digits after the point (decimal part)
Else
valeur(0) = CInt(Int(strch))
valeur(1) = 0
End If
Return valeur
End Function
This method generally works, but for very large numbers, it will not work
Integer: Contains signed 32-bit (4-byte) integers whose value ranges from -2,147,483,648 to 2,147,483,647.
If the number to be tested is outside these limits, another solution must be found (which I am currently looking for :S)