Jump to content

[Resolved] How to round down, not just round?


Recommended Posts

Hi. When I run this script:

$var = DriveSpaceFree($USB_FlashDriveLtr)
MsgBox(4096, "Free space on " & $USB_FlashDriveLtr, $var & " MB")     ; no rounding at all
I get a rounded up value of
996 MB
since the rounding is going to closest number which this time happens to be a higher value. This isn't ideal in this case. It would be better that the return err on the side of caution and report back the closest smaller number. However, I couldn't find anything about rounding _down_. Is it possible to?

Thx. :P

Edited by Diana (Cda)
Link to comment
Share on other sites

Hi. When I run this script:

$var = DriveSpaceFree($USB_FlashDriveLtr)
MsgBox(4096, "Free space on " & $USB_FlashDriveLtr, $var & " MB")     ; no rounding at all
I get a rounded up value of
996 MB
since the rounding is going to closest number which this time happens to be a higher value. This isn't ideal in this case. It would be better that the return err on the side of caution and report back the closest smaller number. However, I couldn't find anything about rounding _down_. Is it possible to?

Thx. :P

Use Floor function.

When the words fail... music speaks.

Link to comment
Share on other sites

Abit early on the morning here but i think you could just cut away everything after "." something like this:

$str = "995.9296875"
$restult = StringLeft($str,StringInStr($str,".")-1)

ConsoleWrite( $restult & @CRLF)

Or offcource use the floor :P

Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Well, this works really well now. Thanks everyone for the tips. I finally figured out how to use this "floor" business <g>, which makes the reporting easier to understand.

I use my own personal UDF now all the time (the one called "partition letters") where I just make one edit when I get to a new computer and it assigns a new letter to my USB flash drive. Computers are locked up at work now so easier to have the one reference that all USB flash drive scripts point to.

In any case, now it's easy to keep track of how much free space there is on the stick with this, which is a simple script. I'll probably fine-tune in the future as I learn more:

;
; AutoIt 3x
;
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon(@ScriptDir & "\USB flash drive, disk space free.ico")


;------ Change target drive(s) to scan here, only: -----------------------
$DriveToScanForFreeSpace = $Work_USB_DriveLtr
;-------------------------------------------------------------------------


$var1 = DriveSpaceFree($DriveToScanForFreeSpace)
$var2 = DriveSpaceFree($DriveToScanForFreeSpace)
$FreeSpace = $var1
$FreeSpaceRoundedDown = Floor($var2)


MsgBox(64,"Free space on the ''" & $DriveToScanForFreeSpace & "\'' UFD drive ...   ","The free space on the ''" & $DriveToScanForFreeSpace & "'' UFD drive is:          " & @CRLF & _
            "-----------------------------------------------     " & @CRLF & @CRLF & _
            $FreeSpace & " MB, exactly" & @CRLF & @CRLF & _
            "or," & @CRLF & @CRLF & _
            $FreeSpaceRoundedDown & " MB, rounded down.")

Cheers. ;)

Edited by Diana (Cda)
Link to comment
Share on other sites

Oh, thought I should add, when I ran this just now, this is the type of output I get:

---------------------------
Free space on the ''F:\'' UFD drive ...   
---------------------------
The free space on the ''F:'' UFD drive is:        

-----------------------------------------------  

986.29296875 MB, exactly

or,

986 MB, rounded down.
---------------------------
OK   
---------------------------

;)

Edited by Diana (Cda)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...