Jump to content

LTRIM or RTRIM?


Recommended Posts

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....

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

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...