{"id":19390,"date":"2021-10-26T19:01:32","date_gmt":"2021-10-26T13:31:32","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=19390"},"modified":"2023-01-04T17:06:08","modified_gmt":"2023-01-04T11:36:08","slug":"round-float-to-2-decimal-places-python-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/","title":{"rendered":"Round float to 2 decimal places Python | Example code"},"content":{"rendered":"\n<p>Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second argument is the <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-string-format-float-precision-example-code\/\">precision <\/a>after the decimal point.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>round(number, digits) <\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example Round float to 2 decimal places Python<\/strong><\/h2>\n\n\n\n<p>Simple example code rounds down to 2 and 3 decimals a float using Python.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(round(1.4756, 2))\n\nprint(round(1.3339, 3))\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"255\" height=\"137\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg?resize=255%2C137&#038;ssl=1\" alt=\"Round float to 2 decimal places Python\" class=\"wp-image-21578\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts or suggestions on this Python float topic.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second argument is the precision after the decimal point. Example Round float to 2 decimal places Python Simple example code rounds down to 2 and 3 decimals a float using Python.&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Round float to 2 decimal places Python | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[249,171],"post_series":[],"class_list":["post-19390","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-decimal","tag-python-float"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Round float to 2 decimal places Python | Example code<\/title>\n<meta name=\"description\" content=\"Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Round float to 2 decimal places Python | Example code\" \/>\n<meta property=\"og:description\" content=\"Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-26T13:31:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-04T11:36:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/\",\"name\":\"Round float to 2 decimal places Python | Example code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg\",\"datePublished\":\"2021-10-26T13:31:32+00:00\",\"dateModified\":\"2023-01-04T11:36:08+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second...\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg?fit=255%2C137&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg?fit=255%2C137&ssl=1\",\"width\":255,\"height\":137},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Round float to 2 decimal places Python | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Round float to 2 decimal places Python | Example code","description":"Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Round float to 2 decimal places Python | Example code","og_description":"Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second...","og_url":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-10-26T13:31:32+00:00","article_modified_time":"2023-01-04T11:36:08+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/","name":"Round float to 2 decimal places Python | Example code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg","datePublished":"2021-10-26T13:31:32+00:00","dateModified":"2023-01-04T11:36:08+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use the round function to Round float to 2 decimal places in Python. This method takes as its first argument the number and the second...","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg?fit=255%2C137&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Round-float-to-2-decimal-places-Python.jpg?fit=255%2C137&ssl=1","width":255,"height":137},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/round-float-to-2-decimal-places-python-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Round float to 2 decimal places Python | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":36121,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-float-precision-to-2\/","url_meta":{"origin":19390,"position":0},"title":"Python float precision to 2","author":"Rohit","date":"February 22, 2023","format":false,"excerpt":"You can use multiple ways to float precision to 2 decimal points in Python. A simple way is used str.format(number) with .2f inside the placeholder, i.e., {:.2f} . This returns a string representation of the number up to two decimal places. str.format(): that formats specific values and inserts them in\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python float precision to 2","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/02\/Python-float-precision-to-2.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":36123,"url":"https:\/\/tutorial.eyehunts.com\/python\/convert-float-to-decimal-python\/","url_meta":{"origin":19390,"position":1},"title":"Convert float to decimal Python","author":"Rohit","date":"February 18, 2023","format":false,"excerpt":"Just pass the float to the Decimal constructor to Convert the float to decimal in Python. Or you can use round(value,2) to return a floating-point number up to two decimal places. from decimal import Decimal Decimal(f) Convert float to decimal Python example Simple example code. from decimal import Decimalf =\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Convert float to decimal Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/02\/Convert-float-to-decimal-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":36102,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-float-decimal-places\/","url_meta":{"origin":19390,"position":2},"title":"Python float decimal places","author":"Rohit","date":"July 11, 2023","format":false,"excerpt":"To specify the number of decimal places when working with floats in Python, you can use string formatting or the round() function. Here's the syntax for each approach: String formatting: formatted_num = \"{:.nf}\".format(num) f-strings (Python 3.6+): formatted_num = f\"{num:.nf}\" round() function: rounded_num = round(num, n) Replace n with the desired\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-float-decimal-places.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":36173,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-decimal-vs-float\/","url_meta":{"origin":19390,"position":3},"title":"Python decimal vs float","author":"Rohit","date":"February 21, 2023","format":false,"excerpt":"The main difference between Python decimal and float is, the float is an Approximate number data type and the Decimal is a Fixed-Precision data type. The float gives you an approximation of the number you declare and decimals represented exactly with precision and scale, it doesn\u2019t round up the value.\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python decimal vs float","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/02\/Python-decimal-vs-float.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":36106,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-float-2-digits-after-dot\/","url_meta":{"origin":19390,"position":4},"title":"Python float 2 digits after dot","author":"Rohit","date":"February 17, 2023","format":false,"excerpt":"Use the round() function to float 2 digits after the dot in Python. Use a certain precision of string formatting when producing output due to floating point imprecision. round(input, digits) Or use the Decimal type: from decimal import Decimalround(Decimal(0.3223322), 2)print(Decimal('0.32')) There are new format specifications, String Format Specification Mini-Language: You\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python float 2 digits after dot","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/02\/Python-float-2-digits-after-dot.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":36224,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-float-format\/","url_meta":{"origin":19390,"position":5},"title":"Python float format","author":"Rohit","date":"February 23, 2023","format":false,"excerpt":"There are various methods for formatting float numbers in Python. The best way is to use the format() function to To format float values in Python. Python float format example Simple example code format float number in python. x = 211911461911461819112146y = 2 ** 70z = x \/ yprint(z)print(\"{:.2f}\".format(z))print(float(\"{:.2f}\".format(z))) #\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python float format","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/02\/Python-float-format.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/19390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=19390"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/19390\/revisions"}],"predecessor-version":[{"id":35301,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/19390\/revisions\/35301"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=19390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=19390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=19390"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=19390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}