An easy set calculation

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Nattugla
Posts: 1
Joined: 31 Jan 2019 02:18

An easy set calculation

#1 Post by Nattugla » 31 Jan 2019 02:44

Hello.

I am not very familiar with Batch Scripts, but I do want to learn.
I am not sure if Batch is the way to go, with what I want to archive.

I work a lot with ink.vat prices to customers, and ex.vat in orders.
I always have to use the calc.exe to calculate (Ink.vat / 1.25) to get the ex.vat.

With Batch. Could I make something that would take the Highlighted value, divide it by 1.25 and then paste/replace the value? Then maybe connect the batch file to a Hotkey.

So I could highlight the ink.vat, hotkey, and now its ex.vat.

Is Batch a good way to go here? Or PowerShell, Autoit...?

Squashman
Expert
Posts: 4106
Joined: 23 Dec 2011 13:59

Re: An easy set calculation

#2 Post by Squashman » 31 Jan 2019 07:39

The set command can only work with 32 bit Integers. It cannot do floating point math. You are better off doing this in Powershell.

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

Re: An easy set calculation

#3 Post by Aacini » 31 Jan 2019 19:34

Code: Select all

@echo off
setlocal

:loop

   set "num="
   set /P "num=Enter integer number: "
   if not defined num goto :EOF

   set /A "div=num*80"
   echo %num% / 1.25 = %div:~0,-2%.%div:~-2%

goto loop
Example:

Code: Select all

Enter integer number: 10
10 / 1.25 = 8.00
Enter integer number: 100
100 / 1.25 = 80.00
Enter integer number: 1000
1000 / 1.25 = 800.00
Enter integer number: 1234
1234 / 1.25 = 987.20
Enter integer number: 123456
123456 / 1.25 = 98764.80
Antonio

Post Reply