• Login
Community
  • Login

The number of digits after the point in the code that is in Notoped++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 3 Posters 2.7k 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.
  • R
    rita252525
    last edited by Jun 17, 2018, 4:21 PM

    Hello.
    I need to reduce the number of digits after the point in the code that is in Notoped++ . For example: in the code 3.6787687 need to be 3.67. Thanks.

    1 Reply Last reply Reply Quote 0
    • T
      Terry R
      last edited by Jun 18, 2018, 2:43 AM

      I might be looking at this the wrong way but if ALL numbers are to be altered then try this:
      Find:(\d+.\d{1,2})\d*
      Replace:\1

      So it doesn’t care how many digits to the left of the “.” as long as there is at least 1 (denoted by the “+”). Then it must have a “.” followed by as many digits as there are, however the first 2 are kept in the ‘saved string’ “\1” which is the replacement.
      If you need to change the number of digits kept after the “.” change the numbers in the {}, i.e. {1,3}.
      A quick test with a number like 1.2 still left it as 1.2, whereas a longer one was truncated back to 2 significant digits. This does NOT round, only truncates which your examples suggests what you want to achieve.

      Terry

      1 Reply Last reply Reply Quote 1
      • T
        Terry R
        last edited by Jun 18, 2018, 3:24 AM

        My previous post had an error. I will blame fat fingers.
        The Find string should be “(\d+.\d{1,2})\d*”. Grab the characters inside the "'s (don’t include the "). The error was with the “.”. As it has special significance in regex’s it needs the “” before it to say we actual want the “.”, not the character group it represents.

        Terry

        1 Reply Last reply Reply Quote 0
        • J
          Jim Dailey
          last edited by Jun 18, 2018, 1:58 PM

          @Terry-R
          I can’t see any difference in your 2 expressions. Did you mean this?

          (\d+\.\d{1,2})\d*
          
          1 Reply Last reply Reply Quote 0
          • R
            rita252525
            last edited by Jun 18, 2018, 4:05 PM

            What to put In the line “to replace” ?

            1 Reply Last reply Reply Quote 0
            • J
              Jim Dailey
              last edited by Jun 18, 2018, 4:38 PM

              @rita252525

              \1
              
              1 Reply Last reply Reply Quote 0
              • T
                Terry R
                last edited by Jun 18, 2018, 7:26 PM

                OK, so it’s not fat fingers it’s poor eyesight. i could swear that the “” was missing, now it’s back again. This time I’ll blame my monitor for rubbing out that character!

                Terry

                1 Reply Last reply Reply Quote 0
                • R
                  rita252525
                  last edited by Jun 19, 2018, 8:21 AM

                  Thank you. It works.

                  1 Reply Last reply Reply Quote 0
                  5 out of 8
                  • First post
                    5/8
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors