-3

I am creating a POS system (Point of Sale system) using batch code. It is all going great, but i am trying to multiply two variables (Quantity of the product) by a set number (the price of the product) and send the output to a separate file, which will be read as the list of final products, or set as a variable. I don't even know if it is possible, but if it is, can someone please help.

If you need further detail, let me know.

itsols
  • 5,406
  • 7
  • 51
  • 95
  • 1
    Your question is too broad. First state what type of programming language or DB you're using or plan to use. – itsols Dec 13 '15 at 13:14
  • possible in Batch - more or less. `set /a` can calculate, but only with integers (and most prices tend to be non-integers). See `set /?` - and please clarify your question - for now it's like "I have a Problem - how do I solve it?" – Stephan Dec 13 '15 at 13:21

1 Answers1

0

In batch, you can use set /a to calculate a number. For instance, if you have a quantity, %quant% which is an integer, and a price %price%, which is an integer too, you can use:

set /a total=%quant%*%price%

If on the other hand your price (like most of the times) is a number with decimals, like 2.99, you can do something like this:

@echo off & setlocal EnableDelayedExpansion
set price=2.00
set quant=5
set "strR=%price:*.=%"
ECHO %strR%>x&FOR %%? IN (x) DO SET /A decimals=%%~z? - 2&del x
set price=%price:.=%
set /a total=%price%*%quant%
for /l %%n in (%decimals% 1 %decimals%) do set total=!total:~0,-%%n!.!total:~-%%n!
echo %total%
pause
Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35