AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Get rid of unwanted zeros

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
[二oO也



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Wed Feb 23, 2005 6:02 pm    Post subject: Get rid of unwanted zeros Reply with quote

How do I get rid of unwanted zeros in a number that I want 1 decimal in:
Like:
23.400000
I have tried Transform, Outvar, Round, %Invar%, 1 but it still returns 6 decimals (like above).
I don't want to use SetFormat because when I "glue" the number together with text, only the text is returned.
I suspect i'm doing something wrong.

Very strange... Confused
_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5068
Location: imaginationland

PostPosted: Wed Feb 23, 2005 6:05 pm    Post subject: Reply with quote

E.g. StringReplace, OutputVar, InputVar, 0, , 1
Back to top
View user's profile Send private message Visit poster's website
[二oO也



Joined: 22 Feb 2005
Posts: 60
Location: Sweden

PostPosted: Wed Feb 23, 2005 6:19 pm    Post subject: Reply with quote

Idea
Ooh, I just remembered that you could use StringTrimRight if you knew that it would always be 5 zeros;
Code:

Num = 23.400000
StringTrimRight, TrimmedNum, Num, 5
;TrimmedNum = 23.4

Very Happy
Hope someone with the same question had some answer on that.
_________________
"Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955)
Back to top
View user's profile Send private message Visit poster's website
Jon



Joined: 28 Apr 2004
Posts: 373

PostPosted: Wed Feb 23, 2005 6:23 pm    Post subject: Reply with quote

Code:
Invar = 23.400000

SetFormat, Float, 0.1

Invar+=0

msgbox, The number is now %Invar%
Back to top
View user's profile Send private message Send e-mail
Dippy46



Joined: 06 Jul 2004
Posts: 171
Location: Manchester, England.

PostPosted: Wed Feb 23, 2005 8:15 pm    Post subject: Reply with quote

@ [二oO也
I've just tested the routine
transform ovar,Round,%ivar%, (your choice)

which is the routine I would have used, buuuut it appears not to work correctly as documented .SHOCK HORROR.
Maybe chris will pick up on this one ......
_________________
Simple ideas lie within reach, only of complex minds
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Wed Feb 23, 2005 9:54 pm    Post subject: Reply with quote

Code:
ivar=23.403040000

Loop
{
StringRight, char, ivar, %A_Index% ; read chars from the right
If char = 0
   Continue ; ignore 0's
Cut := (A_Index-1)
StringTrimRight, ovar, ivar, %Cut% ; cut off all found 0's
Break
}

MsgBox, %ovar%


NonMathWorkaround Shocked

Tested. Cool
Commented Cool
Back to top
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Feb 23, 2005 10:01 pm    Post subject: Reply with quote

Interesting as always, BoBo. Very Happy In a good way, of course. Laughing
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Wed Feb 23, 2005 10:25 pm    Post subject: Reply with quote

Quote:
I don't want to use SetFormat because when I "glue" the number together with text, only the text is returned.
I suspect i'm doing something wrong.
I guess you're right Wink

That worked fine Shocked

Code:
ivar = 23.490910test
SetFormat, float, 0.1
ivar += 0.0
Transform, ivar, Round, %ivar%,1
MsgBox, %ivar%


Cool
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group