Problème d'arrondi de chiffre

Résolu
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 4 avril 2006 à 21:30
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 - 4 avril 2006 à 22:31
Bonsoir à tous....

En vbs, j'ai un petit problème pour arrondir un chiffre.
J'ai beau essayé avec Round, CInt, Fix...je n'y arrive pas..pourtant ça parait simple.
J'ai un chiffre "23 456 789" (Koctets) et ma question comment l'arrondir pour avoir
"23 457" (Mo), tout en conservant les espaces (FormatNumber)
Avec ma synthaxe erronée, j'obtiens "23457".

Ci-dessous, mon code complet et en rouge, où je coince.
Ce script analyse la volumétrie des disks fixes.
Merci d'avance,
jean-marc

Call ShowFreePourcent()
MsgBox ShowFreePourcent
Function ShowFreePourcent()
Dim fso, d, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives 'permet de parcourir tous les disks
For Each d in dc
Select Case d.DriveType 'selection en fonction du type de lecteur
' Case 0: s = "Inconnu"
' Case 1: s = " Disk Amovible"' Case 2: s " Disk Fixe" & "> Espace disponible: " & d.AvailableSpace/1024 & " Koctets"
' Case 3: s = " Lecteur Réseau"
' Case 4: s = " Lecteur CD-ROM"
' Case 5: s = " Disk virtuel"

Case 2:
s = "Lecteur " & d.DriveLetter & ":"
s = s & vbCrLf
s = s & "Taille totale : " & FormatNumber(d.TotalSize/1024, 0) & " KOctets" & vbCrLf


s = s & "Taille occupée : " & FormatNumber(FormatNumber(d.TotalSize/1024, 0) - _
FormatNumber(d.AvailableSpace/1024, 0), 0) & " KOctets" & vbCrLf
s = s & "Taille disponible : " & FormatNumber(d.AvailableSpace/1024, 0) & " KOctets" & vbCrLf
s = s & "Pourcentage occupé : " & FormatPercent((FormatNumber(d.TotalSize/1024, 0) -_
FormatNumber(d.AvailableSpace/1024, 0)) / FormatNumber(d.TotalSize/1024, 0)) & vbCrLf
s = s & "Pourcentage libre : " & FormatPercent(FormatNumber(d.AvailableSpace/1024, 0) /_
FormatNumber(d.TotalSize/1024, 0)) & vbCrLf&vbCrLf&_
"taille totale en Mo: " & CInt(FormatNumber(FormatNumber(d.TotalSize/1024, 0) / 1000)) & " Mo"
result = result &vbCrLf& s &vbCrLf
Case Else
End Select
Next
ShowFreePourcent = result
End Function

2 réponses

Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
4 avril 2006 à 22:10
Bonsoir,

FormatNumber est une chaîne et ne doit pas être utilisé dans les calculs

on calcule en numérique et on formate ensuite
et aussi 1 Mo = 1024 Ko



MsgBox "taille totale en Mo: " & FormatNumber(d.ToTalSize / 1024 / 1024, 0)



'la division par 1024 est inutile pour le calcul du pourcentage

s = s & "Pourcentage occupé : " & FormatPercent((d.ToTalSize - d.AvailableSpace) / d.ToTalSize, 0) & vbCrLf




Daniel
3
cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
4 avril 2006 à 22:31
Bonsoir,

Merci, Daniel,
J'ai testé les l'arrondi du % et de Mo en Go.

jean-marc
0
Rejoignez-nous