Is it possible to use a regular expression to perform rounding on a number? The problem is that I’ve got a lot of numbers to more than 2 decimal places in a file and I need to move them to 2 decimal places.
It’s in source file so ideally I’d like to use Visual Studio’s find and replace, but I’m not against the idea of writing a script to run on the file (treating it as plain text) if regex doesn’t have the answer.
You can’t do it with regexes alone, as Ryan pointed out, but you can use regexes to find decimals in your input and use a callback function on the replace operation.
In Python:
The regex to match decimals is very simplistic; it doesn’t match exponential notation, for example, but it should give you an idea.