Rounding Numbers
Numbers
from
WinCustomize Forums
I have a script thats tell's me how much space i have free on the drive i select.
When it gives me a number it is something like H: 236.234375 MB how do i round the number so it will say something like H: 236.2 MB. Also it gives me the right number if it is in megabytes But if it is in gigabytes it will be in the thousands. is there anyway to change that to. It will say C: 9272.34765625 MB instead of C: 9.2 GB Thank You
| 'Let's allocate the object globally, so we don't waste time allocating it on each call Dim objWMIService Dim szDrive Dim menu Dim res Dim fname Sub Object_OnScriptEnter 'If I wasn't so lame I'd write something that would go through the list of drives available and make sure only available drives are here but I'm too lazy for that. object.settimer 123, 2500 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") End Sub Sub Object_OnRButtonUp(x,y,Dragged) Set menu = DesktopX.CreatePopupMenu menu.AppendMenu 0, 1, "C:" menu.AppendMenu 0, 2, "D:" menu.AppendMenu 0, 3, "E:" menu.AppendMenu 0, 4, "F:" menu.AppendMenu 0, 5, "G:" menu.AppendMenu 0, 6, "H:" Dim result result = menu.TrackPopupMenu(&H00000004, System.CursorX, System.CursorY) executecontextmenu(result) End Sub Sub executecontextmenu(n) Select Case n Case 1 fname = "C:" Case 2 fname = "D:" Case 3 fname = "E:" Case 4 fname = "F:" Case 5 fname = "G:" Case 6 fname = "H:" End Select End Sub Sub Object_OnScriptExit Set objWMIService = nothing End Sub Sub Widget_OnPreferencesChange Object_OnTimer123 End Sub Sub Object_OnTimer123 Dim colItems Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk where name = '" & fname & "'",,48) For Each objItem In colItems Object.text = fname &" " & objItem.FreeSpace / 1048576 & " MB" 'we just really need one result here, so we exit Exit Sub Next End Sub |
When it gives me a number it is something like H: 236.234375 MB how do i round the number so it will say something like H: 236.2 MB. Also it gives me the right number if it is in megabytes But if it is in gigabytes it will be in the thousands. is there anyway to change that to. It will say C: 9272.34765625 MB instead of C: 9.2 GB Thank You