It would be nice is someone can help me.
I have text files that looks like this :
#Zsdfgsdqfq
#A100,56
#Zjtdhsdfg
#Zadsdf
#B12,53
#Zdwfgs
#C10,00
#Zdsfgdfg
#D40,00
In the file #A, #B, #C and D# are numbers that I need to divide by 6.55957 This is the result that I want :
#A15,33
#Zjtdhsdfg
#Zadsdf
#B1,91
#Zdwfgs
#C1,52
#Zdsfgdfg
#D6,10
I've found this helpful discussion : Notepad ++ How to multiply numbers from mass replace?
So I used the Python script plugin in Notepad++
I can't figure how to manage decimal numbers and the comma used for decimal separator.
I've discovered I can delete all comas then divide the result by 100 and I will be able to search and replace to replace dots with comas in the resulting file.
Here is my script based on what I read on the linked discussion :
def multiply_number_in_context(match):
return "{0}{1}".format(match.group(1), str(int(match.group(2))/655.957)) # thank you Wiktor Stribiżew to explain me how to get rid of this : ,''
editor.rereplace(r'(\#A)(\d+)', multiply_number_in_context)
editor.rereplace(r'(\#B)(\d+)', multiply_number_in_context)
editor.rereplace(r'(\#C)(\d+)', multiply_number_in_context)
editor.rereplace(r'(\#D)(\d+)', multiply_number_in_context)
Here is the result :
#Zsdfgsdqfq
#A15.33027317339399
#Zjtdhsdfg
#Zadsdf
#B1.910186185984752
#Zdwfgs
#C1.524490172374104
#Zdsfgdfg
#D6.097960689496415
It works but now I need to round the results with two decimals. #A should be 15.33 and #D should be 6.10
It seems the way is using the round(x, 2) thing but I can't figure ho to make this work.
I tried to modify my script with this sort of things this :
return "{0}{1}{2}".format(match.group(1), str(round(int(match.group(2))/655.957), '')), 2)
or to modify the script so it rounds the numbers instead of multiplying but with no success I have syntax errors and such.
It would be kind if someone can improve my script so it rounds the result or give me another script that will round my results.
I don't want to learn programing I'm just searching for a solution.
Thank you.