Calculator answer structure Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Prbumbasas
Posts: 11
Joined: 26 Apr 2021, 07:11

Calculator answer structure

Post by Prbumbasas » 30 Jan 2023, 16:10

Hello, how can I make the answer written only in whole numbers without dot and everything that is below it?

Code: Select all

#Warn
#SingleInstance Force
Gui, Add, Tab2,, Math|Convert
Gui, Font, s12, Arial Nova
;--------------------------
Gui, Add, Text,, Input first number:
Gui, Add, Text,, Choose operator:
Gui, Add, Text,, Input second number:
;-
Gui, Add, Edit, vC1 ym ,20    ;-for test can overwrite
Gui, Add, DropDownList, vOperator, +|-|*|/|^
Gui, Add, Edit, vC2 ,11   ; for test 
;-
Gui, Add, Button, default gA1,CALCULATE
;-
;- next TAB ( not used at moment ) ---
Gui, Tab, 2
Gui, Add, DropDownList, vTypeunit, Temperature|Distance|Mass/Weight|Speed
Gui, Add, ListBox, vTest, Celsius|Fahrenheit|Kelvin
;-
Gui, Show,, SimpleCalc
GuiControl,1: ChooseString,operator,+   ;- for test 
return
;-------------
GuiClose:
Exitapp
;-------------
A1:
Gui, Submit,nohide
result:=""
Switch, Operator
{
Case "+":Result := C1 + C2
Case "*":Result := C1 * C2
Case "-":Result := C1 - C2
Case "/":Result := C1 / C2
Case "^":Result := C1 ** C2
}
MsgBox,% "The answer is: " Result
return
;==========================================


Prbumbasas
Posts: 11
Joined: 26 Apr 2021, 07:11

Re: Calculator answer structure

Post by Prbumbasas » 31 Jan 2023, 08:56

Okey, I fixed that old problem, but right now answer some times is incorect, because sometimes when there is a ".5+" it is changed to a higher number.
How can I fix that problem?

User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: Calculator answer structure  Topic is solved

Post by boiler » 31 Jan 2023, 10:06

That’s what Round() does. Did you try Floor() since that’s apparently what you want?

User avatar
mikeyww
Posts: 26859
Joined: 09 Sep 2014, 18:38

Re: Calculator answer structure

Post by mikeyww » 31 Jan 2023, 10:49

Also:

Code: Select all

#Requires AutoHotkey v1.1.33
n  := -65.5309
; n  :=  65.5309
; n  := -65.
; n  :=  65
; n  := -65
n2 := StrSplit(n, ".")[1]
MsgBox 64, Numbers, % n "`nFloor = " Floor(n) "`nn2 = " n2
image230131-1051-001.png
Output
image230131-1051-001.png (5.38 KiB) Viewed 300 times

RussF
Posts: 1261
Joined: 05 Aug 2021, 06:36

Re: Calculator answer structure

Post by RussF » 31 Jan 2023, 11:17

To simply strip anything after the decimal and leave the integer portion, use:

Code: Select all

Result := Format("{:d}", Result)
It will preserve the sign and won't round either way.

Russ

garry
Posts: 3760
Joined: 22 Dec 2013, 12:50

Re: Calculator answer structure

Post by garry » 31 Jan 2023, 11:29

also an example

Code: Select all

X:= -944.822445
C1:=ceil(x)  ;  -944
C2:=abs(c1)  ;   944  minus removed
msgbox,C1= %c1%`nC2=  %c2%              
return

Code: Select all

SetFormat, float, 0.2
X2:= 2000.827445
C3:=1*x2       ;  2000.83
msgbox,X2=%x2%`nC3=%C3%              
return

Post Reply

Return to “Ask for Help (v1)”