{"id":4706,"date":"2020-09-03T16:14:42","date_gmt":"2020-09-03T10:44:42","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=4706"},"modified":"2020-09-03T16:14:44","modified_gmt":"2020-09-03T10:44:44","slug":"python-round-function-with-examples","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/python-round-function-with-examples\/","title":{"rendered":"Python round() function with EXAMPLES"},"content":{"rendered":"\n<p>The round() function is one of the built-in functions in <a href=\"https:\/\/www.h2kinfosys.com\/blog\/top-10-python-online-tutorials-to-ace-the-language\/\">Python<\/a>. This function is used to round the decimal points to the user-specified number. If the user does not give input, then the round function converts the float into an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Integer\" rel=\"nofollow noopener\" target=\"_blank\">integer<\/a>.<\/p>\n\n\n\n<p>Let\u2019s take a look at code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Rounding Integer Value<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-green-background-color has-background\"><tbody><tr><td>num = 5.2234232<br>print(round(num))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The following is the output.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/uMA0Ywk9Lh1Y8cDzl66JALmVpPk-WU4JHSEl76vPEQoEto85V2CevkyDTsDwocjA8Z9d6Hza0ghNP8af-QzDrVYAB6Z1VYPDwI1uctQAnAHs1HThKa2WSJiyLVWfZiks12wEqjVhPxe6_teY9Q\" alt=\"Rounding Integer Value\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Round function to a specified number.<\/h2>\n\n\n\n<p>The first input to the Python round function is the number that the user wants to round. The second input is the number of digits the user wants after the decimal point.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-green-background-color has-background\"><tbody><tr><td>num = 5.1234567<br>print(round(num,2))<br>print(round(num,3))<br>print(round(num,4))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The following is the output of the above code.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/cz_o_NqGbfuGLy4P4p0QECblve7qEZjRl45lBCrpwBsbbGAF7wA9u2Q_pv7zrX9RGF9jn3TagBsLbHW7pT_rqgo24Vt-tiRHCmpRh84fkuNVuC5Vc-H3i_2Fm2k1_XqevyyceY-TLRP3ALgJEA\" alt=\"Round function\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Rounding Negative Values<\/h2>\n\n\n\n<p>Rounding negative values is the same as a positive value.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-green-background-color has-background\"><tbody><tr><td>m = -5.1234567<br>print(round(num))<br>print(round(num,2))<br>print(round(num,3))<br>print(round(num,4))<br><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Roje27dbb2PCcBiFGn8j6o3V4mC-m5MaxGLGUFj25xRDuK4K-VT9i2b0HQhr0nNCdBizDNuiaeLETTD2gg0zZjRNDydhVF73vW33vH6Q1M26-2Jhk1rhNVjyLjaXZNzkMi7DKX2k7RrahLnJ1Q\" alt=\"Rounding Negative Values\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Rounding Integer<\/h2>\n\n\n\n<p>When we try to round integer, the result remains the same. Let\u2019s have a look at the code.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-green-background-color has-background\"><tbody><tr><td>num = 4<br>print(round(num))<br>print(round(num,2))<br>print(round(num,3))<br>print(round(num,4))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/ZQfMaW8QDzuQtt78y8ukafQ8lD__iN1BJ-OiO7z6bvOeLwX7g1xCPySbAYK1qFyRDOnZdHJ5BGc3to2iNpCTLqWZTPoPaVI6JOasFjqdl7RUMY2CRUe66T2cNqwuSgHQ-3jHDAlrcOoCqLwkGQ\" alt=\"Rounding Integer\" title=\"\"><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The round() function is one of the built-in functions in Python. This function is used to round the decimal points to the user-specified number. If the user does not give input, then the round function converts the float into an integer. Let\u2019s take a look at code. Rounding Integer Value num = 5.2234232print(round(num)) The following [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4736,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[342],"tags":[1326,1327,1328],"class_list":["post-4706","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials","tag-python-round-function","tag-rounding-integer","tag-rounding-negative-values"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4706","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=4706"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4706\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/4736"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=4706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=4706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=4706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}