50%

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mattis95
Posts: 8
Joined: 12 Jan 2012 13:04

50%

#1 Post by Mattis95 » 23 Feb 2012 07:56

I want to create a variable, then remove/add 50% of itself to itself, I thought it should work with this, but it doesn't:

Code: Select all

set hi=60
set /a hi=%hi% * 0.5

Why doesn't it work and how can I make it work?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: 50%

#2 Post by Ed Dyreen » 23 Feb 2012 08:01

'
DOS doesn't support floats have to be emulated.

Code: Select all

set "hi=60"
set /a hi /= 2

Mattis95
Posts: 8
Joined: 12 Jan 2012 13:04

Re: 50%

#3 Post by Mattis95 » 23 Feb 2012 08:03

Ed Dyreen wrote:'

Code: Select all

set "hi=60"
set /a hi /= 2

It worked, but if I want to add 50% of %hi% to %hi%?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: 50%

#4 Post by foxidrive » 23 Feb 2012 08:23

Is this any good?

Code: Select all

@echo off
set hi=60
set /a hi=hi*3/2
set hi
pause

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: 50%

#5 Post by orange_batch » 23 Feb 2012 12:23

Code: Select all

@echo off
set hi=60

set /a hi=hi*30/2
if "%hi:~-1%"=="0" (set hi=%hi:~,-1%) else set hi=%hi:~,-1%.%hi:~-1%

set hi
pause


Returns decimal number to tenths (unless number is an integer).

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: 50%

#6 Post by Aacini » 23 Feb 2012 18:48

@Mattis95: May I suggest you to post better/clearer topic titles for your questions? :wink:

Regards...

Mattis95
Posts: 8
Joined: 12 Jan 2012 13:04

Re: 50%

#7 Post by Mattis95 » 24 Feb 2012 10:08

Aacini wrote:@Mattis95: May I suggest you to post better/clearer topic titles for your questions? :wink:

Regards...

Yea, maybe I should have called it... "Add 50% of itself to itself"?

Post Reply