dbenham wrote:jEval.bat
How many more of these Hybrid Scripts do you got up your sleeve?
Moderator: DosItHelp
dbenham wrote:jEval.bat
Code: Select all
@echo off & cls
setlocal disabledelayedexpansion
rem setting part
rem use only decimal numbers
rem in range of -/+ 214748364
rem you can change decimal sign to ,
set "_1st_number=-21474836"
set "_2nd_number=330"
set "_decimal_sign=,"
rem testing part
set /a "_test=%_1st_number%"
if %errorlevel% neq 0 (echo( & echo(first number is out of range & echo( & pause & goto :eof)
if [%_1st_number%] neq [%_test%] (echo(first number is out of range & echo( & pause & goto :eof)
if %_test% gtr 214748364 (echo(first number is out of range & echo( & pause & goto :eof)
if %_test% lss -214748364 (echo(first number is out of range & echo( & pause & goto :eof)
set /a "_test=%_2nd_number%"
if %errorlevel% neq 0 (echo( & echo(second number is out of range & echo( & pause & goto :eof)
if [%_2nd_number%] neq [%_test%] (echo(second number is out of range & echo( & pause & goto :eof)
if %_test% gtr 214748364 (echo(second number is out of range & echo( & pause & goto :eof)
if %_test% lss -214748364 (echo(second number is out of range & echo( & pause & goto :eof)
set "_test="
rem math part
if %_1st_number% lss 0 (if %_2nd_number% gtr 0 (set "_result_sign=-"))
if %_2nd_number% lss 0 (if %_1st_number% gtr 0 (set "_result_sign=-"))
if %_1st_number% lss 0 (set "_1st_number=%_1st_number:~1%" & set "_1st_number_sign=-")
if %_2nd_number% lss 0 (set "_2nd_number=%_2nd_number:~1%" & set "_2nd_number_sign=-")
set /a "_value1=(%_1st_number%)/(%_2nd_number%)", "_modulus1x10=((%_1st_number%)%%(%_2nd_number%))*(10)"
if %errorlevel% neq 0 (echo( & pause & goto :eof)
set /a "_value2=(%_modulus1x10%)/(%_2nd_number%)", "_modulus2x10=((%_modulus1x10%)%%(%_2nd_number%))*(10)"
set /a "_value3=(%_modulus2x10%)/(%_2nd_number%)", "_modulus3x10=((%_modulus2x10%)%%(%_2nd_number%))*(10)"
set /a "_value4=(%_modulus3x10%)/(%_2nd_number%)"
set "_decimals=%_value2%%_value3%"
if %_value4% gtr 5 (set /a "_decimals+=1")
if %_decimals% gtr 99 (set /a "_value1+=1" & set "_decimals=00")
set "_result=%_result_sign%%_value1%%_decimal_sign%%_decimals%"
echo(%_1st_number_sign%%_1st_number%/%_2nd_number_sign%%_2nd_number%=%_result%
echo(
endlocal
pause
exit /b
Compo wrote:Similar to Dave'sThe 1 after the comma I use to make sure that the result is 'away from zero' midpoint rounded.Code: Select all
@For /F %%A In ('PowerShell -C "[math]::round(7/3,2,1)"') Do @Echo(%%A&Timeout 5
pstein wrote:Compo wrote:Similar to Dave'sThe 1 after the comma I use to make sure that the result is 'away from zero' midpoint rounded.Code: Select all
@For /F %%A In ('PowerShell -C "[math]::round(7/3,2,1)"') Do @Echo(%%A&Timeout 5
Hmm, this does not seem to work:
for /f %%A in ('powershell -command "& {[math]::round(9/8,2)}"') do set "bbb=%%A"
outputs 1,12 (=wrong) instead of 1,13 (=correct)
pstein wrote:Compo wrote:Similar to Dave'sThe 1 after the comma I use to make sure that the result is 'away from zero' midpoint rounded.Code: Select all
@For /F %%A In ('PowerShell -C "[math]::round(7/3,2,1)"') Do @Echo(%%A&Timeout 5
Hmm, this does not seem to work:
for /f %%A in ('powershell -command "& {[math]::round(9/8,2)}"') do set "bbb=%%A"
outputs 1,12 (=wrong) instead of 1,13 (=correct)
Code: Select all
C:\Users\Compo>For /f %A In ('PowerShell -c "[math]::round(9/8,2)"') Do @Echo(%A
1.12
C:\Users\Compo>For /f %A In ('PowerShell -c "[math]::round(9/8,2,1)"') Do @Echo(%A
1.13