• Login
Community
  • Login

How to convert scientific notation to standard?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 5 Posters 2.5k Views
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.
  • S
    sweezy92
    last edited by Oct 20, 2020, 3:32 PM

    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!

    E 1 Reply Last reply Oct 20, 2020, 3:43 PM Reply Quote 0
    • E
      Ekopalypse @sweezy92
      last edited by Oct 20, 2020, 3:43 PM

      @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()))
      
      B 1 Reply Last reply Mar 3, 2024, 12:13 AM Reply Quote 3
      • S
        sweezy92
        last edited by Oct 20, 2020, 4:03 PM

        @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
        • B
          Ben Mcmillan @Ekopalypse
          last edited by Mar 3, 2024, 12:13 AM

          @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?

          P 1 Reply Last reply Mar 3, 2024, 12:54 AM Reply Quote 0
          • P
            PeterJones @Ben Mcmillan
            last edited by Mar 3, 2024, 12:54 AM

            @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.

            B 1 Reply Last reply Mar 4, 2024, 1:45 AM Reply Quote 3
            • B
              Ben Mcmillan @PeterJones
              last edited by Mar 4, 2024, 1:45 AM

              @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?

              M 1 Reply Last reply Mar 4, 2024, 2:00 AM Reply Quote 0
              • M
                Mark Olson @Ben Mcmillan
                last edited by Mar 4, 2024, 2:00 AM

                @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
                • M
                  Mark Olson
                  last edited by Mark Olson Mar 4, 2024, 2:11 AM Mar 4, 2024, 2:11 AM

                  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
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors