How to change decimal precision using Notepad++

I recently had a large JavaScript array – a complex polygon of latitude and longitude coordinates.

The file was undesirably large (about 32 MB) which seemed to stem from the precision of the coordinates being up to 17 decimal places.

Fortunately, the simple yet powerful Notepad++ could help – by using the regex find and replace we can reduce the precision of the coordinates.

To do this,

  1. open the Replace dialogue (Ctrl + H)
  2. under ‘Search mode’ select ‘Regular expression’
  3. in ‘Find what’ enter the following
  4. \d+\.\d{5}\K\d+
  5. leave ‘Replace with’ empty

This will reduce the precision down to 5 decimal places – change the 5 in step 4 for alternatives.

For me, this reduced the file from 32 MB to 15 MB – a massive saving that will result in a faster loading map.