numbers in variables
Posted: 02 Nov 2011 05:00
i want to save some number in variables. for example: 326598745 or 32.659
how to do it?
how to do it?
Code: Select all
set var=12345
Code: Select all
set /a var2=%var%/125
Code: Select all
set /a nom=2.335
Code: Select all
@echo off &setlocal
echo the limit is exceeded
set /a var1=2147483648
echo %var1%
echo(
echo that's the upper bound
set /a var2=2147483647
echo %var2%
echo(
echo that's the lower bound
set /a var3=-2147483647
echo %var3%
echo(
echo that's below the limit
set /a var4=-2147483648
echo %var4%
echo(
echo there are no floating points
set /a var5=3.14159
echo %var5%
echo(
echo there are no thousand separators
set /a var6=1,000,000
echo %var6%
echo(
pause
the limit is exceeded
Ungültige Zahl. Zahlen sind begrenzt auf eine Genauigkeit von 32 Bits.
ECHO ist ausgeschaltet (OFF).
that's the upper bound
2147483647
that's the lower bound
-2147483647
that's below the limit
Ungültige Zahl. Zahlen sind begrenzt auf eine Genauigkeit von 32 Bits.
ECHO ist ausgeschaltet (OFF).
there are no floating points
Fehlender Operator
3
there are no thousand separators
1
Drücken Sie eine beliebige Taste . . .
c:\>set pi=3.14159
c:\>clc 2 * %pi%
6.28318
c:\>clc %pi% ^^ 2
9.8695877281
Code: Select all
clc 2 * %pi%
really?Mohammad_Dos wrote:it does not work for me:Code: Select all
clc 2 * %pi%
Code: Select all
@echo off
>calc.vbs echo WScript.Echo Eval(WScript.Arguments(0))
set pi=3.14159
call:calc 2 * %pi%
call:calc %pi% ^^ 2
del /q calc.vbs
goto:eof
:calc
cscript //nologo calc.vbs "%*"
goto:eof
Judago wrote:I wrote a floating point/large number batch script recently(mostly just for the fun of it).
Judago wrote:I can't guarantee accuracy and it's probably too much code to be really useful.
Code: Select all
@echo off&setlocal enabledelayedexpansion
:: Multiply.
set num=200.333
set operation=*2
call :calcfloat %num% %operation%
:: Divide.
set num=500.222
set operation=/2
call :calcfloat %num% %operation%
pause
exit
:: Float Math
:calcfloat
for /f "delims=. tokens=1*" %%a in ("%1") do (
call :getlength %%b
set pad=
for /l %%c in (1,1,!length!) do set pad=0!pad!
set /a result=%%a!pad!%2+%%b%2
)
set "result=!result:~,-%length%!.!result:~-%length%!"
echo: ^> Result: %result%
exit/b
:: Length, max 2048 chars.
:getlength
set "lengthstr=x%~1"
set length=0
for /l %%a in (10,-1,0) do (
set /a "length|=1<<%%a"
for /f "delims=" %%b in ("!length!") do if "!lengthstr:~%%b,1!"=="" set /a "length&=~1<<%%a"
)
exit/b