Jump to content
Sign in to follow this  
Tripredacus

LTRIM or RTRIM?

Recommended Posts

Tripredacus

I haven't dealt with TRIM functions in a long time so I can't remember which of these I need. I have written a GUI that displays the total physical memory in the computer, divides it by 1,024,000 and displays as GB. On this computer it displays the physical memory as 2.04594921875 GB, but I want it to display as 2.045 GB. I searched the help file but there is no result for LTRIM or RTRIM. Obviously those are database terms...

Here is the relevant code:

$mem = MemGetStats()
$pmem = ( $mem[1] / 1024000 )
$Label_16 = GuiCtrlCreateLabel($pmem, 130, 160)

Also, right now I use a label for the GB. Is it possible to put the GB into the $pmem variable? like this:

$pmem = ( $mem[1] / 1024000 & " GB" )

I do not know the syntax to put text following a operation....

Share this post


Link to post
Share on other sites
Jos

Trim, LTrim and Rtrim are functions to strip the spaces at the start or end of a string. AutoIt3 = StringStripWS() which does it all.

But... you want to remove the decimals i assume so just use INT(Formule)....

:)

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
PsaltyDS

The functions StringTrimLeft() and StringTrimRight() are for... strings.

If you want to trim a number, use Round():

$a = 2.04594921875
$b = Round($a, 3)
MsgBox(64, "Round()", $a & " = " & $B)

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Tripredacus

How about this?

$mem = MemGetStats()
$pmem = ( Round ($mem[1] / 1048576, 2) & " GB")
$Label_16 = GuiCtrlCreateLabel($pmem, 130, 160)
You got the 1048576 by 1024*1024, but it should be 1024*1000?

Yes this function works well, but I changed it to 3, since some computers will have less than 1GB in it.

Share this post


Link to post
Share on other sites
GMK

You got the 1048576 by 1024*1024, but it should be 1024*1000?

Yes this function works well, but I changed it to 3, since some computers will have less than 1GB in it.

Actually 1,024 MB = 1 GB

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.