 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
[二oO也
Joined: 22 Feb 2005 Posts: 60 Location: Sweden
|
Posted: Wed Feb 23, 2005 6:02 pm Post subject: Get rid of unwanted zeros |
|
|
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...  _________________ "Make everything as simple as possible, but not simpler."
- Albert Einstein (1879-1955) |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5068 Location: imaginationland
|
Posted: Wed Feb 23, 2005 6:05 pm Post subject: |
|
|
| E.g. StringReplace, OutputVar, InputVar, 0, , 1 |
|
| Back to top |
|
 |
[二oO也
Joined: 22 Feb 2005 Posts: 60 Location: Sweden
|
Posted: Wed Feb 23, 2005 6:19 pm Post subject: |
|
|
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
|
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 |
|
 |
Jon
Joined: 28 Apr 2004 Posts: 373
|
Posted: Wed Feb 23, 2005 6:23 pm Post subject: |
|
|
| Code: | Invar = 23.400000
SetFormat, Float, 0.1
Invar+=0
msgbox, The number is now %Invar% |
|
|
| Back to top |
|
 |
Dippy46
Joined: 06 Jul 2004 Posts: 171 Location: Manchester, England.
|
Posted: Wed Feb 23, 2005 8:15 pm Post subject: |
|
|
@ [二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 |
|
 |
BoBo Guest
|
Posted: Wed Feb 23, 2005 9:54 pm Post subject: |
|
|
| 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
Tested.
Commented  |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Feb 23, 2005 10:01 pm Post subject: |
|
|
Interesting as always, BoBo. In a good way, of course.  |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Feb 23, 2005 10:25 pm Post subject: |
|
|
| 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
That worked fine
| Code: | ivar = 23.490910test
SetFormat, float, 0.1
ivar += 0.0
Transform, ivar, Round, %ivar%,1
MsgBox, %ivar% |
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|