{"id":19064,"date":"2016-12-11T20:02:01","date_gmt":"2016-12-11T20:02:01","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=19064"},"modified":"2016-12-11T20:09:47","modified_gmt":"2016-12-11T20:09:47","slug":"perl-round-off","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-round-off\/","title":{"rendered":"Perl: round off"},"content":{"rendered":"<h1>The tutor gives a way to round numbers in Perl.<\/h1>\n<p>To my knowledge, the best way to round a number in Perl is with its built-in <span style=\"font-family:monospace;font-size:120%\">printf()<\/span> or <span style=\"font-family:monospace;font-size:120%\">sprintf()<\/span>.<\/p>\n<p>To round with <span style=\"font-family:monospace;font-size:120%\">printf()<\/span>:<\/p>\n<ol>\n<li>\nLet&#8217;s imagine the number is stored in the variable <span style=\"font-family:monospace;font-size:120%\">$num<\/span>.\n<\/li>\n<li>\nTo display the number rounded to its nearest integer, use the command<br \/>\n<span style=\"font-family:monospace;font-size:120%\">printf(&#8220;%.0f&#8221;,$num);<\/span>\n<\/li>\n<\/ol>\n<p>To round with <span style=\"font-family:monospace;font-size:120%\">sprintf()<\/span>:<\/p>\n<ol>\n<li>\nLet&#8217;s imagine the number is stored in the variable <span style=\"font-family:monospace;font-size:120%\">$num<\/span>.\n<\/li>\n<li>\nTo display the number rounded to its nearest integer, use the command<br \/>\n<span style=\"font-family:monospace;font-size:120%\">print(sprintf(&#8220;%.0f&#8221;,$num));<\/span>\n<\/li>\n<\/ol>\n<p>For more info about <span style=\"font-family:monospace;font-size:120%\">printf()<\/span> or <span style=\"font-family:monospace;font-size:120%\">sprintf()<\/span>, see my post <a href=\"?p=7340\">here<\/a>.<\/p>\n<p>HTH:)<\/p>\n<p>Source:<\/p>\n<p><a href=\"http:\/\/www.sthomas.net\/roberts-perl-tutorial.htm\">Robert&#8217;s Perl tutorial<\/a><\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/178539\/how-do-you-round-a-floating-point-number-in-perl\">stackoverflow.com<\/a><\/p>\n<p>McGrath, Mike.  <u>Perl in easy steps<\/u>.  Southam:  Computer Step, 2004.<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor gives a way to round numbers in Perl. To my knowledge, the best way to round a number in Perl is with its built-in printf() or sprintf(). To round with printf(): Let&#8217;s imagine the number is stored in &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-round-off\/\"> <span class=\"screen-reader-text\">Perl: round off<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[104,379,2065,380],"class_list":["post-19064","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-perl","tag-printf","tag-rounding-to-nearest-integer","tag-sprintf"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/19064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=19064"}],"version-history":[{"count":13,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/19064\/revisions"}],"predecessor-version":[{"id":19078,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/19064\/revisions\/19078"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=19064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=19064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=19064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}