Problème avec mon probramme VBA

Résolu/Fermé
novice53 Messages postés 5 Date d'inscription mercredi 25 juin 2014 Statut Membre Dernière intervention 17 juillet 2014 - 17 juil. 2014 à 12:40
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 - 17 juil. 2014 à 15:20
Bonjour,

j'ai écrit un programme en VBA qui me permet de faire une approximation de mes nombres c-a-d
quand j'ai un nombre de 12.3000000 mon approximation me donne 12.3
mon problème est le suivant quand mon nombre est entier l'approximation de ce nombre est suivi d'une virgule
exemple: 90 approximation me donne 90,
quand j'ai un nombre entier sans decimal mon approximation me fait apparaitre la virgule derière ce nombre entier, chose que je veux pas

s'il vous plait quelqu'un pourrait me dire comment faire pour qu'elle n'apparait plus merci

Function approximation(Point As String) As String

Dim approx As Double


If Val(Point) < 0 Then
approx = -0.0005
Else
approx = 0.0005
End If

Point = Str(Val(Point) + approx)
Point = Mid(Point, 1, InStr(Point, ".") + 3)

If InStr(Point, "-") = 1 Then
If InStr(Point, "") = 2 Then Point = "-0" + Mid(Point, 2, Len(Point))
Else
If InStr(Point, ".") = 1 Then Point = "0" + Point
End If

If InStr(Point, " ") = 1 Then
Point = Mid(Point, 1, Len(Point))
End If

If Right(Point, 4) = ".000" Then
Point = Left(Point, Len(Point) - 3)
End If

If Right(Point, 2) = "00" Then
Point = Left(Point, Len(Point) - 2)
End If

If Right(Point, 1) = "0" Then
Point = Left(Point, Len(Point) - 1)
End If

If Val(Point) = 0 Then Point = "0"


approximation = Point

End Function

1 réponse

pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
17 juil. 2014 à 12:59
Bonjour,

Quel est l'intérêt d'une telle fonction???

Sinon, pour ton souci ajoute ceci en fin de code :
If Right(Point, 1) = "," Then Point = Left(Point, Len(Point) - 1) 

0
novice53 Messages postés 5 Date d'inscription mercredi 25 juin 2014 Statut Membre Dernière intervention 17 juillet 2014
17 juil. 2014 à 14:04
slt pojaku
merci pour ton aide, j' avais même pas pensé qu'il falait réécrire une nouvelle condition.
je suis débutant dans le language informatique, et j'apprend en faisant certaine programation.

l'intérêt de ma fonction est de ne plus utiliser le format de celule nombre d'excel mais le mien uniquement.
je fait beaucoup de calcul sur excel c'est our cette raison.
je te remerci pour ton aide
0
pijaku Messages postés 12263 Date d'inscription jeudi 15 mai 2008 Statut Modérateur Dernière intervention 4 janvier 2024 2 744
17 juil. 2014 à 15:20
de rien.
A+
0