1

I'm comparing some files with Beyond Compare (3.3).
I have some minor diffs on floating point numbers.

Is there a way to tell BC to ignore such differences after a certain decimal place?

Adi Shavit
  • 477
  • 3
  • 6
  • 17
  • Set up Beyond Compare to compare two files / folders. Once the compare windows are open, View and then select Unimportant Differences. I do not think this will ignore different numbers as you have requested. – John Apr 12 '22 at 12:46

2 Answers2

1

Beyond Compare's Text Compare can't ignore differences after a certain decimal place.

Differences can be ignored as text, either as plain text or regular expressions.

As an example, to ignore all numeric characters after a decimal point:

  1. Open files in Beyond Compare 3's Text Compare.
  2. Click the Rules toolbar button (referee icon).
  3. Go to the Importance tab.
  4. Click the Edit Grammar button.
  5. In the top half of the Grammar tab, click New.
  6. Name: Unimportant Number.
  7. Category: Basic
  8. Text matching: .\d+
  9. Check Regular expression and click OK.
  10. Click OK.
  11. Uncheck Unimportant Number in the grammar element list to make it unimportant.
  12. Click OK.
  13. Make sure View > Ignore Unimportant Differences is on.
Chris Kennedy
  • 411
  • 2
  • 3
  • Cool - I wonder if it isn't possible to add to the reg-exp several indicators to match the first _n_ digits after the decimal point. – Adi Shavit Apr 24 '22 at 08:17
  • 1
    \d+ matches on one or more numeric characters. To match on 2 characters after the decimal point, use \d{2} or \d\d as the regular expression. See the Regular Expression Reference in Beyond Compare's help file for more information. – Chris Kennedy Apr 25 '22 at 15:39
  • Nice solution. Just wanted to mention that .\d+ will not only match the . but any single character followed by digits. What you want is \.\d+. Also be aware that this solution will not solve numerical jitter around the integer portion of the number. If the left side says 0.99 and the right side says 1.02, the match will not be ignored. – Cerno Jun 01 '22 at 07:23
0

I would like to extend the accepted answer a little bit.

First, you should use \.\d+ with an backslash before the . otherwise the . will match any character.

With the accepted solution, you might run into numerical problems you do not want, for example if you want to compare 0.99 with 1.01.

As far as I know there is no perfect solution in Beyond Compare for this, but you can reduce the number of mismatches by defining the Grammar as a List instead of Basic which allows you to have multiple rules.

If you set up the list like this:

\.\d+
(0|1)\.\d+
(1|2)\.\d+
(2|3)\.\d+
(3|4)\.\d+
(4|5)\.\d+
(5|6)\.\d+
(6|7)\.\d+
(7|8)\.\d+
(8|9)\.\d+
(9|0)\.\d+

you will be able to catch an overrun by a single integer place before the ..

However, this will not work for more integer places, so if you have 109.99 and 110.01, this will fail and still show up as a difference. I tried to add more rules to support more integer places, like (09|10)\.\d+, but that did not seem to work.

Some other corner cases like .9 vs 1.0 will also not work, so be advised that both the accepted solution and mine are not perfect, but they might help you cut down on unwanted differences.

Cerno
  • 101
  • 1
  • 3