Check out my function
Hello all.
I am working with a bunch of numbers in an NSIS script I made, and wanted to add the commas (1,450,884) to them to make them easier to read. I put this little function together because I could not find anything on the Wiki. Feel free to point out anything I may have missed that would have done what this does, or if there is a better way to program what I did below. Thanks all.
- Handles up to 12 digit numbers
- Sets error flag if over 12 digits
- Ignores numbers 3 digits and less
- Preserves stack and register variables values once complete(I think :rolleyes: )
Push $0 ;$0 = 1450884
Call CommaNum
Pop $0 ;$0 = 1,450,884
Function CommaNum
Exch $0
Push $1
Push $2
Push $3
Push $4
Push $5
StrLen $1 $0
IntCmp $1 3 Done Done
IntCmp $1 6 0 0 +5
StrCpy $2 $0 -3
StrCpy $3 $0 "" -3
StrCpy $0 "$2,$3"
Goto Done
IntCmp $1 9 0 0 +6
StrCpy $2 $0 -6
StrCpy $3 $0 3 -6
StrCpy $4 $0 "" -3
StrCpy $0 "$2,$3,$4"
Goto Done
IntCmp $1 12 0 0 Error
StrCpy $2 $0 -9
StrCpy $3 $0 3 -9
StrCpy $4 $0 3 -6
StrCpy $5 $0 "" -3
StrCpy $0 "$2,$3,$4,$5"
Goto Done
Error:
SetErrors
Done:
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd