X-Git-Url: https://git.immae.eu/?p=perso%2FDenise%2Foms.git;a=blobdiff_plain;f=gestion_unites.py;h=f4cc38ece48032755dca6bc34c9cec7318672e9b;hp=d4089bd9c0e0dbafad3ea67820730094845505df;hb=cf0d4c8c36224ca7059e99d03c25abaf694011d7;hpb=a680b2f78891692be215013481e167da2fffb5d8 diff --git a/gestion_unites.py b/gestion_unites.py index d4089bd..f4cc38e 100644 --- a/gestion_unites.py +++ b/gestion_unites.py @@ -3,6 +3,7 @@ from configuration import CONFIG from gestion_erreurs import warning +from math import log ##################### outils pour affichage et choix de l'unité @@ -94,4 +95,18 @@ def convertitunite(jours,unite,liste_err): def convertit_tableau(tableau,unite,liste_err): """ convertit un tableau de jours en une autre unité. Renvoie le nouveau tableau""" - return [convertitunite(elt,unite,liste_err) for elt in tableau] \ No newline at end of file + return [convertitunite(elt,unite,liste_err) for elt in tableau] + +def arrondit_donnee(donnee, typed, arrondi=0): + """ on arrondit la donnée de type typed (à voir dans CONFIG) + à arrondit près. SI y'a 0 on va voir dans la config. + Pour l'arrondit on met par ex 1 pour arrondir à 1 pr_s, 0.1 pour arrondir + au dixième etc""" + if arrondi==0: + arrondi = CONFIG["arrondis_typedonnees"][typed] + if arrondi==0: + print("Euuuh ça va merder, y'a une div par 0 dans arrondit_donnees !") + + d_arr = round(donnee/arrondi)*arrondi + nbchiffresvoulus = int(log(1/arrondi, 10))+1 # max sur le nombre de chiffres après la virgule qu'on doit avoir + return round(d_arr, nbchiffresvoulus) \ No newline at end of file