Why does +e canceled and -e not?












4















System.out.println(2e+5);


Above line's output is,



200000.0




While below line's,



System.out.println(2e-5);


output is,



2.0e-5




Why does 2e-5 is not solved down with -10^5 giving the output,



0.00002









share|improve this question

























  • One reason may be, that in the first case the extra digits may hold significant information, while in the second case they are always zero.

    – Henry
    Jul 20 '18 at 17:04











  • Because you're relying on the default formatting rules. 2e-5 is a double literal - it's 64 ones and zeroes. There is no format, no notation, no decimal point. How its represented when printed is just that, a representation. It's meaningless.

    – Boris the Spider
    Jul 20 '18 at 17:05













  • @Henry the extra digits in 2eanything will always be zero...

    – Boris the Spider
    Jul 20 '18 at 17:06











  • @BoristheSpider in this case yes, but take 1.23456e5 and 1.23456e-5 for example.

    – Henry
    Jul 20 '18 at 17:08











  • In both cases you have shown numbers represented to 6 s.f. @Henry. All the digits are significant - that's what the "s" stands for! I'm really not sure what you mean.

    – Boris the Spider
    Jul 20 '18 at 17:09


















4















System.out.println(2e+5);


Above line's output is,



200000.0




While below line's,



System.out.println(2e-5);


output is,



2.0e-5




Why does 2e-5 is not solved down with -10^5 giving the output,



0.00002









share|improve this question

























  • One reason may be, that in the first case the extra digits may hold significant information, while in the second case they are always zero.

    – Henry
    Jul 20 '18 at 17:04











  • Because you're relying on the default formatting rules. 2e-5 is a double literal - it's 64 ones and zeroes. There is no format, no notation, no decimal point. How its represented when printed is just that, a representation. It's meaningless.

    – Boris the Spider
    Jul 20 '18 at 17:05













  • @Henry the extra digits in 2eanything will always be zero...

    – Boris the Spider
    Jul 20 '18 at 17:06











  • @BoristheSpider in this case yes, but take 1.23456e5 and 1.23456e-5 for example.

    – Henry
    Jul 20 '18 at 17:08











  • In both cases you have shown numbers represented to 6 s.f. @Henry. All the digits are significant - that's what the "s" stands for! I'm really not sure what you mean.

    – Boris the Spider
    Jul 20 '18 at 17:09
















4












4








4








System.out.println(2e+5);


Above line's output is,



200000.0




While below line's,



System.out.println(2e-5);


output is,



2.0e-5




Why does 2e-5 is not solved down with -10^5 giving the output,



0.00002









share|improve this question
















System.out.println(2e+5);


Above line's output is,



200000.0




While below line's,



System.out.println(2e-5);


output is,



2.0e-5




Why does 2e-5 is not solved down with -10^5 giving the output,



0.00002






java numbers double notation scientific-notation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 11:08









Poorna Senani Gamage

96411222




96411222










asked Jul 20 '18 at 16:58









Roshana PitigalaRoshana Pitigala

4,86162549




4,86162549













  • One reason may be, that in the first case the extra digits may hold significant information, while in the second case they are always zero.

    – Henry
    Jul 20 '18 at 17:04











  • Because you're relying on the default formatting rules. 2e-5 is a double literal - it's 64 ones and zeroes. There is no format, no notation, no decimal point. How its represented when printed is just that, a representation. It's meaningless.

    – Boris the Spider
    Jul 20 '18 at 17:05













  • @Henry the extra digits in 2eanything will always be zero...

    – Boris the Spider
    Jul 20 '18 at 17:06











  • @BoristheSpider in this case yes, but take 1.23456e5 and 1.23456e-5 for example.

    – Henry
    Jul 20 '18 at 17:08











  • In both cases you have shown numbers represented to 6 s.f. @Henry. All the digits are significant - that's what the "s" stands for! I'm really not sure what you mean.

    – Boris the Spider
    Jul 20 '18 at 17:09





















  • One reason may be, that in the first case the extra digits may hold significant information, while in the second case they are always zero.

    – Henry
    Jul 20 '18 at 17:04











  • Because you're relying on the default formatting rules. 2e-5 is a double literal - it's 64 ones and zeroes. There is no format, no notation, no decimal point. How its represented when printed is just that, a representation. It's meaningless.

    – Boris the Spider
    Jul 20 '18 at 17:05













  • @Henry the extra digits in 2eanything will always be zero...

    – Boris the Spider
    Jul 20 '18 at 17:06











  • @BoristheSpider in this case yes, but take 1.23456e5 and 1.23456e-5 for example.

    – Henry
    Jul 20 '18 at 17:08











  • In both cases you have shown numbers represented to 6 s.f. @Henry. All the digits are significant - that's what the "s" stands for! I'm really not sure what you mean.

    – Boris the Spider
    Jul 20 '18 at 17:09



















One reason may be, that in the first case the extra digits may hold significant information, while in the second case they are always zero.

– Henry
Jul 20 '18 at 17:04





One reason may be, that in the first case the extra digits may hold significant information, while in the second case they are always zero.

– Henry
Jul 20 '18 at 17:04













Because you're relying on the default formatting rules. 2e-5 is a double literal - it's 64 ones and zeroes. There is no format, no notation, no decimal point. How its represented when printed is just that, a representation. It's meaningless.

– Boris the Spider
Jul 20 '18 at 17:05







Because you're relying on the default formatting rules. 2e-5 is a double literal - it's 64 ones and zeroes. There is no format, no notation, no decimal point. How its represented when printed is just that, a representation. It's meaningless.

– Boris the Spider
Jul 20 '18 at 17:05















@Henry the extra digits in 2eanything will always be zero...

– Boris the Spider
Jul 20 '18 at 17:06





@Henry the extra digits in 2eanything will always be zero...

– Boris the Spider
Jul 20 '18 at 17:06













@BoristheSpider in this case yes, but take 1.23456e5 and 1.23456e-5 for example.

– Henry
Jul 20 '18 at 17:08





@BoristheSpider in this case yes, but take 1.23456e5 and 1.23456e-5 for example.

– Henry
Jul 20 '18 at 17:08













In both cases you have shown numbers represented to 6 s.f. @Henry. All the digits are significant - that's what the "s" stands for! I'm really not sure what you mean.

– Boris the Spider
Jul 20 '18 at 17:09







In both cases you have shown numbers represented to 6 s.f. @Henry. All the digits are significant - that's what the "s" stands for! I'm really not sure what you mean.

– Boris the Spider
Jul 20 '18 at 17:09














2 Answers
2






active

oldest

votes


















8














Because that's how the designers of the Double class chose to implement it:




[...]




  • If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('u002E'), followed by one or more decimal digits representing the fractional part of m.

  • If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." [...]




They could have made another choice, of course, but that's simply how it is.



As the documentation says, if you want a specific format, use a NumberFormat to format your double.






share|improve this answer































    0














    As already pointed out by @Nizet, when converting double to string, the output will have scientific notation if number of digits are large. And this is not just for decimals.



    Consider:



    double d = 1500000000;
    System.out.println(String.valueOf(d));


    This will print 1.5E9



    If you want conversion to happen in readable format, use String.format



    System.out.println(String.format ("%.0f", d));


    will print 1500000000






    share|improve this answer
























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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%2fstackoverflow.com%2fquestions%2f51447263%2fwhy-does-e-canceled-and-e-not%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









      8














      Because that's how the designers of the Double class chose to implement it:




      [...]




      • If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('u002E'), followed by one or more decimal digits representing the fractional part of m.

      • If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." [...]




      They could have made another choice, of course, but that's simply how it is.



      As the documentation says, if you want a specific format, use a NumberFormat to format your double.






      share|improve this answer




























        8














        Because that's how the designers of the Double class chose to implement it:




        [...]




        • If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('u002E'), followed by one or more decimal digits representing the fractional part of m.

        • If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." [...]




        They could have made another choice, of course, but that's simply how it is.



        As the documentation says, if you want a specific format, use a NumberFormat to format your double.






        share|improve this answer


























          8












          8








          8







          Because that's how the designers of the Double class chose to implement it:




          [...]




          • If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('u002E'), followed by one or more decimal digits representing the fractional part of m.

          • If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." [...]




          They could have made another choice, of course, but that's simply how it is.



          As the documentation says, if you want a specific format, use a NumberFormat to format your double.






          share|improve this answer













          Because that's how the designers of the Double class chose to implement it:




          [...]




          • If m is greater than or equal to 10-3 but less than 107, then it is represented as the integer part of m, in decimal form with no leading zeroes, followed by '.' ('u002E'), followed by one or more decimal digits representing the fractional part of m.

          • If m is less than 10-3 or greater than or equal to 107, then it is represented in so-called "computerized scientific notation." [...]




          They could have made another choice, of course, but that's simply how it is.



          As the documentation says, if you want a specific format, use a NumberFormat to format your double.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 20 '18 at 17:15









          JB NizetJB Nizet

          547k588941021




          547k588941021

























              0














              As already pointed out by @Nizet, when converting double to string, the output will have scientific notation if number of digits are large. And this is not just for decimals.



              Consider:



              double d = 1500000000;
              System.out.println(String.valueOf(d));


              This will print 1.5E9



              If you want conversion to happen in readable format, use String.format



              System.out.println(String.format ("%.0f", d));


              will print 1500000000






              share|improve this answer




























                0














                As already pointed out by @Nizet, when converting double to string, the output will have scientific notation if number of digits are large. And this is not just for decimals.



                Consider:



                double d = 1500000000;
                System.out.println(String.valueOf(d));


                This will print 1.5E9



                If you want conversion to happen in readable format, use String.format



                System.out.println(String.format ("%.0f", d));


                will print 1500000000






                share|improve this answer


























                  0












                  0








                  0







                  As already pointed out by @Nizet, when converting double to string, the output will have scientific notation if number of digits are large. And this is not just for decimals.



                  Consider:



                  double d = 1500000000;
                  System.out.println(String.valueOf(d));


                  This will print 1.5E9



                  If you want conversion to happen in readable format, use String.format



                  System.out.println(String.format ("%.0f", d));


                  will print 1500000000






                  share|improve this answer













                  As already pointed out by @Nizet, when converting double to string, the output will have scientific notation if number of digits are large. And this is not just for decimals.



                  Consider:



                  double d = 1500000000;
                  System.out.println(String.valueOf(d));


                  This will print 1.5E9



                  If you want conversion to happen in readable format, use String.format



                  System.out.println(String.format ("%.0f", d));


                  will print 1500000000







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jul 20 '18 at 17:17









                  HariUserXHariUserX

                  1,0881415




                  1,0881415






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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%2fstackoverflow.com%2fquestions%2f51447263%2fwhy-does-e-canceled-and-e-not%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

                      List item for chat from Array inside array React Native

                      Thiostrepton

                      Caerphilly