Community
    • Login

    How to convert scientific notation to standard?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 5 Posters 3.6k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • sweezy92S Offline
      sweezy92
      last edited by

      Hello,

      I have a text file with data like this:

      *Name: 1
      55.0021 1.1E1
      103.9542 4.0E-1
      …

      Name: 1
      …*

      I want to convert the numbers in scientific notation into standard decimals. There is no other way for me to export the data. So I need to do it here. Could you help me?

      Thanks!

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE Offline
        Ekopalypse @sweezy92
        last edited by

        @sweezy92

        depending on your real data and that you have python script plugin installed
        this might do what you want

        editor.rereplace('\d+?\.\d+?E\-*\d', lambda m: float(m.group()))
        
        Ben McmillanB 1 Reply Last reply Reply Quote 3
        • sweezy92S Offline
          sweezy92
          last edited by

          @Ekopalypse said in How to convert scientific notation to standard?:

          editor.rereplace(‘\d+?.\d+?E-*\d’, lambda m: float(m.group()))

          I just installed the plugin and tried the code. It works perectly. Thanks a lot!

          1 Reply Last reply Reply Quote 3
          • Ben McmillanB Offline
            Ben Mcmillan @Ekopalypse
            last edited by

            @Ekopalypse
            great idea. The scientific notation in my doc is slightly different, It has:

            1.0000E-001
            and
            1.0000E+001

            as examples.
            What should the script be please?

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP Offline
              PeterJones @Ben Mcmillan
              last edited by

              @Ben-Mcmillan ,

              Instead of -*, which looks for 0 or more minus signs (I personally would have used -?, so it’s 0 or 1), use [+-]? , which would be 0 or 1 minus or plus signs. And then instead of the final \d , use \d+ to allow more than one digit in the exponent.

              Ben McmillanB 1 Reply Last reply Reply Quote 3
              • Ben McmillanB Offline
                Ben Mcmillan @PeterJones
                last edited by

                @PeterJones thanks. If I’m understanding correctly, this should be the final script:

                editor.rereplace('\d+?\.\d+?E\[+-]?\d+', lambda m: float(m.group()))
                

                but it doesn’t seem to do anything to my doc. Have I made a mistake?

                Mark OlsonM 1 Reply Last reply Reply Quote 0
                • Mark OlsonM Offline
                  Mark Olson @Ben Mcmillan
                  last edited by

                  @Ben-Mcmillan
                  m.group() needs to take an integer as its first and only argument.
                  For example, m.group(0) returns the full text of the match, and m.group(n) returns the n^th capture group.

                  1 Reply Last reply Reply Quote 0
                  • Mark OlsonM Offline
                    Mark Olson
                    last edited by Mark Olson

                    This regex will capture all scientific notation numbers, and can also handle leading + signs and number with leading decimal points:
                    ([+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?)

                    Seriously, everyone should just write that down somewhere so they can look it up in times of need.

                    1 Reply Last reply Reply Quote 4

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors