Code: Select all
ClipBoard =
(
1000.00
2000.00
3000.00
4000.00
)
; ^^^ this is to simulate what is on your clipboard for this test
MsgBox, % fnSumNumericLines(ClipBoard)
fnSumNumericLines(InputVar) {
Loop, Parse, InputVar, `r`n
Result += A_LoopField
Result := Format("{:.2f}", Result) ; if you want it formatted
Return Result
}
See
https://www.autohotkey.com/docs/commands/Format.htm for other ways you could format
Result
I created it as a function to make it more portable/reusable throughout your code. You could even make some of the "format" into a parameter you supply, something like this example, specifying decimal places (but defaulting to 2):
Code: Select all
ClipBoard =
(
1000.00
2000.00
3000.00
4000.00
)
; ^^^ this is to simulate what is on your clipboard for this test
MsgBox, % fnSumNumericLines(ClipBoard, 2)
MsgBox, % fnSumNumericLines(ClipBoard, 0)
MsgBox, % fnSumNumericLines(ClipBoard, 4)
MsgBox, % fnSumNumericLines(ClipBoard) ; no second parameter - uses function "default" of 2
fnSumNumericLines(InputVar, DecimalPlaces:=2) {
Loop, Parse, InputVar, `r`n
Result += A_LoopField
Result := Format("{:." DecimalPlaces "f}", Result)
Return Result
}