Sign in to follow this  
Followers 0
danrche

Integer to Float HELP

7 posts in this topic

Hello all,

I'm trying to convert an integer like '1073741824' (which is = about 1BG in bytes) to a Float to look like 1GB

Here's the code I've used in Vbscript

'''''''''''''''' VBscript Function ''''''''''''''''''''''

Function size(Bytes)

If Bytes >= 1073741824 Then

size = FormatNumber(Bytes \ 1024 \ 1024 \ 1024, 2) & " GB"

End If

End Function

''''''''''''''' End Vbscript ''''''''''''''''''''''''''''''

but I don't know autoit enough to do the same. :)

I just want a conversion function that i can pass my variables to and convert to a float for easier reading

Thanks Ahead of time for your suggestions, recommendations, and help.

also, how do I add tags for this post?

Daniel

Share this post


Link to post
Share on other sites



This should do the trick for you:

MsgBox(0, "", _ConvertToMyNeeds(102004578888))

Func _ConvertToMyNeeds($Number)
    Select
        Case $Number > 0 And $Number < 1024
            Return $Number&" Bytes"
        Case $Number >= 1024 And $Number < 1048576
            Return Round($Number/1024)&" KB"
        Case $Number >= 1048576 And $Number < 1073741824
            Return Round($Number/1048576)&" MB"
        Case $Number >= 1073741824
            Return Round($Number/1073741824)&" GB"
    EndSelect
EndFunc

If the values I have used for MB, GB ... are wrong, change them to the correct ones (I have used 1024, 1024^2, 1024^3 ...)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

enaiman, cool thanks, that's actually just what I'm looking to do. I was trying to do it with stringformat though, but couldn't figure it out, your way much easier :)

Share this post


Link to post
Share on other sites

danrche,

This is a rough approximation following your VBScript code. Did NOT do any searching but imagine that you can find all kinds of routines in this forum.

;
;
;

local $bytes = 9356922358, $size

If $Bytes >= 1073741824 Then
$size = $Bytes / 1024 / 1024 / 1024 & " GB"
Endif

consolewrite( $size & @lf)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

$iSize = 102004578888
$tData = DllStructCreate('wchar[80]')

$Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatByteSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80)
MsgBox(0, '', DllStructGetData($tData, 1))

$Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatKBSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80)
MsgBox(0, '', DllStructGetData($tData, 1))

Share this post


Link to post
Share on other sites

$iSize = 102004578888
$tData = DllStructCreate('wchar[80]')

$Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatByteSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80)
MsgBox(0, '', DllStructGetData($tData, 1))

$Ret = DllCall('shlwapi.dll', 'ptr', 'StrFormatKBSizeW', 'uint64', $iSize, 'ptr', DllStructGetPtr($tData), 'uint', 80)
MsgBox(0, '', DllStructGetData($tData, 1))

OOOO this is nice too, Thanks for the input. I never event looked at DLLCall before.

Do you know how I can populate an array and sort on this? This is both learning and actual need for me. I'm trying to write an app much like dirsize that runs through your folders and spits out the top ten largest folders. I've been using logparser 2.2 with "Select Top 10 * into c:\bigfile.csv From C:\* order by size desc" =-i:FS -recurse:1 -o:csv

it works great, but I don't want to install logparser on all the machines, plus I don't learn to code that way either :)

Share this post


Link to post
Share on other sites

Answered some of my own questions here, #include <Array.au3>

_ArrayAdd and _ArraySort

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0