Numeric content of a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jorgegs
Posts: 22
Joined: 07 Apr 2016 22:56

Numeric content of a variable

#1 Post by Jorgegs » 27 Apr 2016 06:01

Good morning friends

First: Thanks for all your helps.

I need to know the last number of a %var% numeric content,
which length I do'nt know because is the result of a mathematic operation with /a
To ask in a batch file.

Thanks in advance for your attention

Jorgegs

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: Numeric content of a variable

#2 Post by einstein1969 » 27 Apr 2016 07:35

try:

Code: Select all

C:\Users\ACER>set /A num=56
56
C:\Users\ACER>echo %num:~-1%
6

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Numeric content of a variable

#3 Post by jeb » 27 Apr 2016 07:37

Or use the modulus operator "%"

Code: Select all

set /a num=1234
set /a remain=num %% 10


The percent have to be doubled here, to avoid that it is removed by the parser

Jorgegs
Posts: 22
Joined: 07 Apr 2016 22:56

Re: Numeric content of a variable

#4 Post by Jorgegs » 28 Apr 2016 05:51

Thank you very much for your help

It's work perfect

Post Reply