Hack Forums
[Shell] floatADD :function to add floating points in batch - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] floatADD :function to add floating points in batch (/showthread.php?tid=5843267)



floatADD :function to add floating points in batch - ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™ - May 31, 2018

Hello all ^-^

Maybe you saw that you can now divide whole integers into floating points from THIS THREAD

But now you can add them using this function!

[Image: ef1714466b1f4ce94ebbbf770d8edc92.png]

Code
rem MUST have at least 4 digits behind decimal point
call :floatADD 1.5000 1.2000
call :floatADD 32.6123 51.0932

:floatADD
set "i=0" & for %%a in (%~1 %~2) do set /a "i+=1" & for /f "tokens=1,2 delims=." %%b in ("%%a") do ( set "s!i!=%%b" & set "f!i!=%%c" )
set /a "j=i-1" & for /l %%a in (1,1,!j!) do ( set /a "n=%%a + 1" & for %%b in (!n!) do ( set /a "w=!s%%a! + !s%%b!", "f=(1!f%%a! + 1!f%%b!) - 20000" ) )
if !f! gtr 10000 set /a "w=!w! + !f:~0,1!" & set "f=!f:~1!"
if "!f:~3!" equ "" set "f=0!f!"
if "%~3" neq "" ( set "%~3=!w!.!f!" ) else ( echo %~1 + %~2 = !w!.!f! )
goto :eof



RE: floatADD :function to add floating points in batch - Erhan - Jun 1, 2018

Thank you very much for very useful batch script!!!