{"id":2585,"date":"2017-06-21T18:54:07","date_gmt":"2017-06-21T16:54:07","guid":{"rendered":"http:\/\/www.unicoda.com\/?p=2585"},"modified":"2017-06-21T16:49:41","modified_gmt":"2017-06-21T14:49:41","slug":"cobol-compute-rounded","status":"publish","type":"post","link":"https:\/\/www.unicoda.com\/?p=2585","title":{"rendered":"COBOL : COMPUTE ROUNDED"},"content":{"rendered":"<p>Une petite notion de COBOL pour par exemple trouver quelques centimes par ci, quelques centimes par l\u00e0.<\/p>\n<p>Il s&rsquo;agit de l&rsquo;utilisation du param\u00e8tre ROUNDED dans l&rsquo;\u00e9criture d&rsquo;un COMPUTE<\/p>\n<h3>Les variables<\/h3>\n<p><code>01 W-NOMBRE1             PIC S9(15)V99 COMP-3.<br \/>\n01 W-NOMBRE2             PIC S9(15)V99 COMP-3.<br \/>\n01 W-MULTIPLICATEUR      PIC S9(3)V9(6) COMP-3.<br \/>\n01 W-RESULTAT1           PIC S9(15)V99 COMP-3.<br \/>\n01 W-RESULTAT2           PIC S9(15)V99 COMP-3.<br \/>\n01 W-EDIT9               PIC +ZZZ.ZZZ.ZZZ.ZZZ.ZZ9,99.<\/code><\/p>\n<h3>Le code d&rsquo;exemple<\/h3>\n<p><code>DISPLAY '----------ROUNDED DEBUT -------------'<br \/>\nMOVE 123,12      TO W-NOMBRE1<br \/>\nMOVE 567,56      TO W-NOMBRE2<br \/>\nMOVE 456,456789  TO W-MULTIPLICATEUR<br \/>\nMOVE 0           TO W-RESULTAT1<br \/>\nMOVE 0           TO W-RESULTAT2<\/code><\/p>\n<p><code>COMPUTE W-RESULTAT1 ROUNDED = W-NOMBRE1<br \/>\n* W-NOMBRE2<br \/>\n* W-MULTIPLICATEUR<\/code><\/p>\n<p><code>COMPUTE W-RESULTAT2 = W-NOMBRE1<br \/>\n* W-NOMBRE2<br \/>\n* W-MULTIPLICATEUR<\/code><\/p>\n<p><code>MOVE W-RESULTAT1 TO W-EDIT9<br \/>\nDISPLAY 'ROUNDED\u00a0\u00a0\u00a0 : ' W-EDIT9<\/code><\/p>\n<p><code>MOVE W-RESULTAT2 TO W-EDIT9<br \/>\nDISPLAY 'NOT ROUNDED: ' W-EDIT9<\/code><\/p>\n<p><code>MOVE 0 TO W-RESULTAT1<br \/>\nMOVE 0 TO W-RESULTAT2<\/code><\/p>\n<p><code>COMPUTE W-RESULTAT1 ROUNDED = W-NOMBRE1<br \/>\n* W-NOMBRE2<br \/>\n- W-MULTIPLICATEUR<\/code><\/p>\n<p><code>COMPUTE W-RESULTAT2 = W-NOMBRE1<br \/>\n* W-NOMBRE2<br \/>\n- W-MULTIPLICATEUR<\/code><\/p>\n<p><code>MOVE W-RESULTAT1 TO W-EDIT9<br \/>\nDISPLAY '<span style=\"font-family: Courier New;\">ROUNDED\u00a0\u00a0\u00a0 <\/span>: ' W-EDIT9<\/code><\/p>\n<p><code>MOVE W-RESULTAT2 TO W-EDIT9<br \/>\nDISPLAY 'NOT <span style=\"font-family: Courier New;\">ROUNDED<\/span>: ' W-EDIT9<\/code><\/p>\n<p><code>DISPLAY '----------ROUNDED FIN -------------'<\/code><\/p>\n<h3>La sysout<\/h3>\n<p><code>----------ROUNDED DEBUT -------------<br \/>\n<span style=\"font-family: Courier New;\">ROUNDED\u00a0\u00a0\u00a0 <\/span>: +         31.896.281,66<br \/>\nNOT <span style=\"font-family: Courier New;\">ROUNDED<\/span>: +         31.896.281,65<br \/>\n<span style=\"font-family: Courier New;\">ROUNDED\u00a0\u00a0\u00a0 <\/span>: +             69.421,53<br \/>\nNOT <span style=\"font-family: Courier New;\">ROUNDED<\/span>: +             69.421,53<br \/>\n----------ROUNDED FIN -------------<\/code><\/p>\n<h3>R\u00e9sultats r\u00e9els<\/h3>\n<p>Pour le premier calcul : 31.896.281,6590951<\/p>\n<p>Pour le second : 69421,530411<\/p>\n<h3>Conclusion<\/h3>\n<p>Comme l&rsquo;explique la documentation Cobol, ROUNDED arrondi la derni\u00e8re d\u00e9cimale en l&rsquo;augmentant de 1 si la d\u00e9cimale suivante en trop d\u00e9passe ou est \u00e9gale \u00e0 5. Vrai dans le premier calcul faut dans le second.<\/p>\n<p>Notez que le comportement\u00a0normal est la troncature des d\u00e9cimaux en trop par rapport \u00e0 la variable de r\u00e9ception du COMPUTE.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Une petite notion de COBOL pour par exemple trouver quelques centimes par ci, quelques centimes par l\u00e0. Il s&rsquo;agit de l&rsquo;utilisation du param\u00e8tre ROUNDED dans l&rsquo;\u00e9criture d&rsquo;un COMPUTE Les variables 01 W-NOMBRE1 PIC S9(15)V99 COMP-3. 01 W-NOMBRE2 PIC S9(15)V99 COMP-3. 01 W-MULTIPLICATEUR PIC S9(3)V9(6) COMP-3. 01 W-RESULTAT1 PIC S9(15)V99 COMP-3. 01 W-RESULTAT2 PIC S9(15)V99 COMP-3. &hellip; <a href=\"https:\/\/www.unicoda.com\/?p=2585\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;COBOL : COMPUTE ROUNDED&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[243,3,40],"tags":[],"class_list":["post-2585","post","type-post","status-publish","format-standard","hentry","category-cobol","category-code","category-info"],"_links":{"self":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/2585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2585"}],"version-history":[{"count":7,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/2585\/revisions"}],"predecessor-version":[{"id":2593,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=\/wp\/v2\/posts\/2585\/revisions\/2593"}],"wp:attachment":[{"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.unicoda.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}