Batch Script use Math to Convert a positive number to negativeBatch convert *.avi files using ffmpegBATCH SET...

What will be the benefits of Brexit?

Word describing multiple paths to the same abstract outcome

What if somebody invests in my application?

Visiting the UK as unmarried couple

How to prevent YouTube from showing already watched videos?

Is exact Kanji stroke length important?

Teaching indefinite integrals that require special-casing

The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?

Why are all the doors on Ferenginar (the Ferengi home world) far shorter than the average Ferengi?

How to check participants in at events?

Organic chemistry Iodoform Reaction

Simple image editor tool to draw a simple box/rectangle in an existing image

Would it be legal for a US State to ban exports of a natural resource?

Calculating the number of days between 2 dates in Excel

Meta programming: Declare a new struct on the fly

Giant Toughroad SLR 2 for 200 miles in two days, will it make it?

Can somebody explain Brexit in a few child-proof sentences?

How can I successfully establish a nationwide combat training program for a large country?

The most efficient algorithm to find all possible integer pairs which sum to a given integer

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

Does "Dominei" mean something?

Resetting two CD4017 counters simultaneously, only one resets

Bob has never been a M before

Is there a problem with hiding "forgot password" until it's needed?



Batch Script use Math to Convert a positive number to negative


Batch convert *.avi files using ffmpegBATCH SET unable to use divide operatorhow to use Null is Batch scriptPassing optional parameters in a batch scriptBatch convert flv to mkv with mkvmergeClose batch script windowwget.exe in batch script, save result to variableHow Can I convert My Batch Script to an Executable and still run like a Bat Script?batch increment variable stringRun as Full Screen a EXE File With Batch Script













0















I have this code:



set /a A=1 + 2

echo A=%A%


the output is A=3



How can I convert this into a negative value? (ie, -3)










share|improve this question




















  • 1





    Simply multiply with -1 set /a A*=-1

    – LotPings
    Feb 13 at 8:24
















0















I have this code:



set /a A=1 + 2

echo A=%A%


the output is A=3



How can I convert this into a negative value? (ie, -3)










share|improve this question




















  • 1





    Simply multiply with -1 set /a A*=-1

    – LotPings
    Feb 13 at 8:24














0












0








0








I have this code:



set /a A=1 + 2

echo A=%A%


the output is A=3



How can I convert this into a negative value? (ie, -3)










share|improve this question
















I have this code:



set /a A=1 + 2

echo A=%A%


the output is A=3



How can I convert this into a negative value? (ie, -3)







windows batch-file cmd.exe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 13 at 12:20









Hennes

59.3k793143




59.3k793143










asked Feb 13 at 8:20









Hüseyin Teoman DenizHüseyin Teoman Deniz

204




204








  • 1





    Simply multiply with -1 set /a A*=-1

    – LotPings
    Feb 13 at 8:24














  • 1





    Simply multiply with -1 set /a A*=-1

    – LotPings
    Feb 13 at 8:24








1




1





Simply multiply with -1 set /a A*=-1

– LotPings
Feb 13 at 8:24





Simply multiply with -1 set /a A*=-1

– LotPings
Feb 13 at 8:24










2 Answers
2






active

oldest

votes


















0














Simply multiply it with -1:



set /a A=1 + 2

set /a A=%A%*-1
echo A=%A%





share|improve this answer































    0














    Just negate it with the - operator



    set A=2
    set /a A = -A


    That's the standard way in almost every programming language. It should also be more readable and slightly more efficient than multiplying with -1



    In fact you don't even need /A in this case, set A=-%A% also works





    share























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1405157%2fbatch-script-use-math-to-convert-a-positive-number-to-negative%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Simply multiply it with -1:



      set /a A=1 + 2

      set /a A=%A%*-1
      echo A=%A%





      share|improve this answer




























        0














        Simply multiply it with -1:



        set /a A=1 + 2

        set /a A=%A%*-1
        echo A=%A%





        share|improve this answer


























          0












          0








          0







          Simply multiply it with -1:



          set /a A=1 + 2

          set /a A=%A%*-1
          echo A=%A%





          share|improve this answer













          Simply multiply it with -1:



          set /a A=1 + 2

          set /a A=%A%*-1
          echo A=%A%






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 13 at 12:09









          rahuldottechrahuldottech

          3,52432548




          3,52432548

























              0














              Just negate it with the - operator



              set A=2
              set /a A = -A


              That's the standard way in almost every programming language. It should also be more readable and slightly more efficient than multiplying with -1



              In fact you don't even need /A in this case, set A=-%A% also works





              share




























                0














                Just negate it with the - operator



                set A=2
                set /a A = -A


                That's the standard way in almost every programming language. It should also be more readable and slightly more efficient than multiplying with -1



                In fact you don't even need /A in this case, set A=-%A% also works





                share


























                  0












                  0








                  0







                  Just negate it with the - operator



                  set A=2
                  set /a A = -A


                  That's the standard way in almost every programming language. It should also be more readable and slightly more efficient than multiplying with -1



                  In fact you don't even need /A in this case, set A=-%A% also works





                  share













                  Just negate it with the - operator



                  set A=2
                  set /a A = -A


                  That's the standard way in almost every programming language. It should also be more readable and slightly more efficient than multiplying with -1



                  In fact you don't even need /A in this case, set A=-%A% also works






                  share











                  share


                  share










                  answered 7 mins ago









                  phuclvphuclv

                  10.4k64295




                  10.4k64295






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1405157%2fbatch-script-use-math-to-convert-a-positive-number-to-negative%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

                      Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

                      VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...