## Formatting Numbers

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

### Formatting Numbers

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)

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

### Re: Formatting Numbers

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

### Re: Formatting Numbers

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.

Then in my code, I do this:
`ResetNormalFormats()y := rtrim(y,0)`
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

### Re: Formatting Numbers

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?
jeeswg
Posts: 4787
Joined: 19 Dec 2016, 01:58
Location: UK

### Re: Formatting Numbers

- 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: 944
Joined: 11 Jan 2017, 17:59

### Re: Formatting Numbers

`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")}`
BGM
Posts: 419
Joined: 20 Nov 2013, 20:56
GitHub: bgmCoder
Contact:

### Re: Formatting Numbers

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.