remove number over four un json
-
Hello, i have a json file with geometry points
to get a lightweight file i would to have not more four number after the coma, so remove the last two if there six nunbers etc
how can i do
thank a lot for your help -
to give you more explanations
in my json i have geometry points , like this
[x.xxxxxx,yy.yyyyyy]before the . (point) it can be one or two x (same for y),
and these x and y can be with -
before … after the coma the number of x and y variesi would to keep only 4 numbers after the . (point)
so
[-95.960683,35.622691]become
[-95.9606,35.6226]but
[9.6021,-45.6081]stay
[9.6021,-45.6081]if you have ideas
thanks -
Thank you for the example, because I would not have interpreted your original question in that way at all.
So what you’re really saying is that you want to truncate any floating-point numbers to only four digits after the decimal. (Thank you for wanting truncation; that’s much easier than rounding – in fact, for the general case, true rounding requires a scripting solution rather than pure regex.)
- FIND =
(?<=\d\.\d{4})\d+ - REPLACE = empty
- SEARCH MODE = regular expression
The FIND is using a lookbehind assertion
(?<=...)to say that “what’s inside this assertion must come before”. Inside the assertion, it’s looking for a digit\dfollowed by a literal period\.(the\is required to make the.be treated as a literal character instead of the special regex meaning of “. matches any character”), followed by four digits\d{4}(where{4}is a multiplying operator). After the assertion, it’s looking for one or more digits\d+(+is another multiplying operator). Because of the lookbehind, the digit+dot+four-digits aren’t part of the “match”, so only the 5th digit and beyond are part of the match – so only 5th digit and beyond get replaced with nothing (since the REPLACE is empty).[-95.960683,35.622691] [9.6021,-45.6081] [3.1415,-2.718281828]becomes
[-95.9606,35.6226] [9.6021,-45.6081] [3.1415,-2.7182]Thank you again for the example data: showing examples of what should be changed and what shouldn’t be changed is very useful to give us things to test our example regular expressions before posting.
- FIND =
-
thanks Peter
I will test -
seems to work very well thanks Peter
-
done well works
and nowin some i have a space after the coma
examples
[-95.9606, 35.6226] or [5.4208, -147.1686]
how to remove this space
to get
[-95.9606,35.6226] or [5.4208,-147.1686]thanks
-
i have made this on you model, which seems to work
search
(?<=\d\.\d{4})\,replace
,
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