Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use batch processing to realize Calculator function

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use batch processing to achieve calculator function, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article. Let's learn about it!

A small calculator made with bat/ batch processing

This is my own small calculator made with bat/ batches. Copy the attached code directly to notepad and save it in .bat format.

Expressions are supported, such as input: 1212 / (7-5); but only integer calculations are supported, not decimals.

It is not very useful and the technical content is not very high, but the process control is still good. Think that logic and abstract thinking are still very strong, and shamelessly narcissistic.

As follows:

The code is as follows:

@ echo off

Cls

:: System Parameter

Set xpProgName=DosCalculator

Set xpProgVer=1.0.0.1

Echo.

Title Welcome to the mini calculator (DCal.bat)% xpProgName%_V%xpProgVer% compiled by Taoether

Color 1f

Rem mode con cols=80 lines=40

Echo Welcome to the mini calculator (DCal.bat)% xpProgName%_V%xpProgVer% compiled by Taoether

If / I {% 1} = = {} goto Main

If / I "% 1" = = "C" goto Main

If / I "% 1" = = "H" goto help

If / I "% 1" = = "V" goto ver

: Ver

Echo.

Rem important statement:

Rem this program is written by Tao Yongli, you can spread it at will, but please do not delete the following information!

If rem is used for commercial purposes, please contact the author.

Echo Version:

Echo--

Echo Program:% xpProgName%

Echo Author: Taoether

Echo Version:% xpProgVer%

Echo IssueTime: 09:01 2009-2-18

Echo UpdateTime: 9:01 2009-6-5

Echo Email: taoether@gmail.com

Echo HomePage: www.taoyoyo.net

Echo--

Echo.

Echo Version Log:

Echo--

Echo Ver. Date. Log.

Echo--

Echo V1000 20090218 New program issue.

Echo V1001 20090605 Add new function: Clear.

Echo...

Echo--

If / I {% 1} = = {} goto Main

If / I "% 1" = = "H" goto end

If / I "% 1" = = "V" goto end

: help

Echo.

Echo Help:

Echo--

Echo this program is a calculator. After entering the calculation expression, the calculation result is returned.

Echo.

Echo DCal [M]

Echo.

Echo [M]: specify the mode in which to run

Echo = null, enter calculation mode

Echo = C, clear screen

Echo = H, show help

Echo = V, display version

Echo.

Echo description:

Echo.

Echo 1, in computing mode:

Enter the formula directly by echo, and enter to return the calculation result.

Echo press E to exit the program

Echo press H to display help

Echo press V to display the version

Echo.

Echo 2, which implements simple calculations and supports the following operations in descending order of priority:

Echo.

Echo ()-grouping

Echo * /%-arithmetic operator

Echo +-arithmetic operator

Echo ^ >-logical shift

Echo-bitwise "and"

Echo ^-bitwise "different"

Echo ^ |-Bitwise OR

Echo = * = /% = + =-=-assignment

Echo ^ & = ^ = ^ | = ^ =-binary operation assignment

Echo,-expression delimiter

Echo.

Echo if you use any logical or rounding operators, you need to enclose the expression string in quotation marks.

Echo any non-numeric string keys in the expression are used as environment variable names, and the values of these environment variable names are converted to numbers before use.

Echo if an environment variable name is specified but not defined in the current environment, the value is set to zero.

Echo this allows you to use environment variable values for calculations without having to type those% symbols to get their values.

Echo if SET / An is executed on a command line other than the command script, it displays the last value of the expression.

Echo the assigned operator requires an environment variable name to the left of the assigned operator.

Echo has 0x prefix except hexadecimal, and octal has 0 prefix, the numeric value is decimal.

Echo therefore, 0x12 is the same as 18 and 022.

Echo, please note that octal formulas can be easily confused: 08 and 09 are invalid numbers because 8 and 9 are not valid octal digits.

Echo--

If / I {% 1} = = {} goto Main

If / I "% 1" = = "H" goto end

If / I "% 1" = = "V" goto end

: Main

Echo.

Echo enters calculation mode: (display help: press H; display version: press V; clear screen: press C; exit: press E)

Echo.

: Calc

Set / p input= Please enter the expression:

If / I "% input%" = = "E" goto end

If / I "% input%" = = "H" goto help

If / I "% input%" = = "V" goto Ver

If / I "% input%" = = "C" goto Clear

Set / a result=%input%

The result of echo calculation is:% input%=%result%

Echo.

Goto Calc

: Clear

Cls

If / I {% 1} = = {} goto Main

If / I "% 1" = = "H" goto end

If / I "% 1" = = "V" goto end

: end

Echo.

Echo wishes you every success in your work and a happy mood!

Echo.

Simplified version:

The code is as follows:

@ echo off

: Calc

Set / p input= Please enter the expression:

Set / a result=%input%

The result of echo calculation is:% input%=%result%

Goto Calc

A calculator is made with batch processing, and the code is as follows

The code is as follows:

@ echo off

: xixi

Set / an a=NULL

Cls

Set x =

Set / p x = expression:

Set / an aversion% x% > > nul

Echo result:% a%

Ping-n 5 127.1 > nul

Goto xixi

For example, input: 4587, 45487, 49864-1546545, 42431355, 54641, 15464, 554, 54545, 564354, 1234365.

You will find that the result is: 208728936

Another example: 12Compare 125x1215 + (13241x12412) * 41545

The result is: 1065755100 you can use parentheses, for more information, please see the detailed usage of set.

Copy the code into the pasted notepad and change the suffix name of the notepad to .bat double-click to run directly.

The above is all the contents of the article "how to use batch processing to achieve calculator functions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report