Formatting Numbers

Get help with using AutoHotkey and its commands and hotkeys
User avatar
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Formatting Numbers

22 Apr 2018, 18:11

Oh, I am completely bewildered by this.

In my script, when I do math with division, I get numbers in scientific format - with e's in them (I'm writing a calculator app)

610*2.17 = 1.3237000000000000e+003

My code is long and complicated and I'm not sure what I did to get this to happen.
What do I look for, and how do I get it to just give me 2 decimal points?

Now, I have this which I am using to switch back to regular numbers (because I switch to hex in another place)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

swagfag
Posts: 1103
Joined: 11 Jan 2017, 17:59

Re: Formatting Numbers

23 Apr 2018, 08:51

why are u appending a "g"?
User avatar
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Formatting Numbers

23 Apr 2018, 09:26

At one time I thought it would help eliminate the trailing zeros...

So, I've removed the g and the +1 and now it's not doing exponents any more so it's not so horrendous.
Then I use rtrim() to remove trailing zeros.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Then in my code, I do this:

Code: [Select all] [Download] GeSHi © Codebox Plus

ResetNormalFormats()
y := rtrim(y,0)
User avatar
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Formatting Numbers

23 Apr 2018, 10:00

So, with this format for the float, it always gives me trailing zeros, and the setformat is undoing my rtrim due to it's global nature and the different threads.
Also, you can use setformat to format both decimals AND floats simultaneously without having to know ahead of time what kind of value you have.

Is there a way to change the parameter for setformat FLOAT so that there are no trailing zeros after the decimal?
User avatar
jeeswg
Posts: 4992
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Formatting Numbers

23 Apr 2018, 13:28

- SetFormat isn't available in AutoHotkey v2, so you could try getting used to the Format function instead. See FORMAT FUNCTION EXAMPLES, here:
jeeswg's characters tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=26486
swagfag
Posts: 1103
Joined: 11 Jan 2017, 17:59

Re: Formatting Numbers

23 Apr 2018, 14:10

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox, % formatFloatTrimZero(610 * 2.17)
MsgBox, % formatFloatTrimZero(610 * 2.171231234122342352623)
MsgBox, % formatFloatTrimZero(610 * 2.171231234122342352623, 10)
MsgBox, % formatFloatTrimZero(610 * 2)

formatFloatTrimZero(floatNum, decimalPlace := 6) {
if floatNum is integer
throw Exception("Illegal argument passed to function " . A_ThisFunc . "().`nSpecifically: Integer (" . floatNum . ")")

return RTrim(Format("{:0." . decimalPlace . "f}", floatNum), "0")
}
User avatar
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

Re: Formatting Numbers

26 Apr 2018, 17:01

Thanks y'all, but my problem is that SetFormat has a global effect; my script is a bit old (from before it was deprecated), and I'm not sure how to change things so that I could work on each variable. Maybe someone could take a look at my script and give me some advice?

I'll leave these links here for awhile; I don't really want them public, but it's okay for awhile, I think.

This is the math part:
https://gist.github.com/BGMcoder/2d6e1e ... 98a369714b

This is the part where the math function is called, so you can see how it is returned to the GUI.
https://gist.github.com/BGMcoder/f29b70 ... a2d569ed53

Problem is that SetFormat in the math part doesn't affect the settings in the GUI part.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], ozz, SpeedMaster and 100 guests