Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4124 Vizualizări

Hello,
Any idea how to round the sum of the two conditions below? I'm not sure how to write the code to achieve this. Thank you!

This is our code in the salary rule:


if worked_days.WORK100:
     result = worked_days.WORK100.number_of_days
if worked_days.WORK110:
    result += worked_days.WORK110.number_of_days


basically we want to get the sum first before rounding the value so adding just round() after the = sign wont do.



Imagine profil
Abandonează

Hello,

Could you just round before assignment? I assume after this statement you assign the variable result to a value on worked_days.

if worked_days.WORK100:

result = worked_days.WORK100.number_of_days

if worked_days.WORK110:

result += worked_days.WORK110.number_of_days

# variable assignment

worked_days.sum = round(result)

Does this work?

Autor

Hi Jack,

i am getting this error "Wrong python code defined for salary rule"

Cel mai bun răspuns

I believe you can use the function round().

example :

if worked_days.WORK100.number_of_days outputs a value of 6.4323157

you can user round(worked_days.WORK100.number_of_days, 2) to output the value 6.43
The second argument of the round function specifies the number of decimals to round to.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
nov. 21
21
0
nov. 21
3279
1
ian. 23
2447
1
aug. 22
2020
2
ian. 22
4734