Last active
October 20, 2020 09:01
-
-
Save agoulziprod/e58b3d2fc66ad538fb027a50e89e123e to your computer and use it in GitHub Desktop.
fixing floating values errors, 12.299995 =>12.3, or 12.360000125 to 12.36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dc:=ds.DonneeClinique.all() | |
For each ($donnee;$dc) | |
$text:=String($donnee.poids_kg) | |
If ($text#"") | |
$numbers:=Split string($text;".") | |
If ($numbers.length=2) | |
$E:=$numbers[0] | |
$flotante:=$numbers[1] | |
If (Length($flotante)>2) | |
$nines_position:=Position("999";$flotante) | |
$zeros_position:=Position("000";$flotante) | |
If ($nines_position>0) | |
$flotante_splited:=Split string($flotante;"") | |
$flotante_splited.resize($nines_position-1) | |
$flotante_splited[$flotante_splited.length-1]:=String(Num($flotante_splited[$flotante_splited.length-1])+1) | |
$new_foltante_string:=$flotante_splited.join("") | |
$new_flotante:=Num("0."+$new_foltante_string) | |
$new_fixed_value:=Num($E)+$new_flotante | |
$donnee.poids_kg:=$new_fixed_value | |
$donnee.save() | |
Else | |
If ($zeros_position>0) | |
$flotante_splited:=Split string($flotante;"") | |
$flotante_splited.resize($zeros_position-1) | |
$new_foltante_string:=$flotante_splited.join("") | |
$new_flotante:=Num("0."+$new_foltante_string) | |
$new_fixed_value:=Num($E)+$new_flotante | |
$donnee.poids_kg:=$new_fixed_value | |
$donnee.save() | |
End if | |
End if | |
End if | |
End if | |
End if | |
End for each |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment