Hello, @david-wanke, @perterjones and All,
David, I saw your post yesterday but I hadn’t time to reply, because I’ve just thought about some rounding cases, shown by Peter !
Of course, with a regex, no problem to change, for instance :
The floating number 12.45678 into the number 12.457
And the floating number 12.45623 into the number 12.456
using the rules :
If the fourth decimal digit, after the decimal point, is between 0 and 4, just truncate all decimal digits after the third one
If the fourth decimal digit, after the decimal point, is between 5 and 9, increase by one the third digit and truncate all decimal digits after the third one
But, as regular expressions, mainly, do string operations, I would have, given the second rule, to take in account all values of the third decimal digit : if 3 then replace by 4, if 7 then replace by 8 and so on… ! And what about rounding 12.99962 which should give 13.000 !
So, it’s easy to understand that the rounding process is, fundamentally, a mathematical operation, which is usually handled by programming or script languages. For instance, in the Peter’s Python script, the line, below, does the mathematical operation ( I’m not a python expert but I don’t think I’m wrong about it !! )
while start < end:
....
rounded = round( float(text) , 3 )
....
As Peter said, this an example of the limitations of regular languages ;-))
Best Regards,
guy038
P.S. :
Refer to some Wiki documentation, below :
https://en.wikipedia.org/wiki/Regular_expression
https://en.wikipedia.org/wiki/Regular_language
Just note that I did not understand most of the second article, anyway ! But, it’s good, from time to time, to feel oneself, very intelligent… during some seconds ;-))