{"id":130,"date":"2010-07-01T17:06:08","date_gmt":"2010-07-01T21:06:08","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2010\/07\/01\/java-method-to-round-a-number-to-specified-decimal-places\/"},"modified":"2010-07-01T17:06:08","modified_gmt":"2010-07-01T21:06:08","slug":"java-method-to-round-a-number-to-specified-decimal-places","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2010\/07\/01\/java-method-to-round-a-number-to-specified-decimal-places\/","title":{"rendered":"Java method to round a number to specified decimal places"},"content":{"rendered":"<p>Example: roundToDecimals(1.23456, 2) will return 1.23.<\/p>\n<pre class=\"code\">\npublic static float roundToDecimals(float fl, int roundToThisManyDecimalPoints) {\n\tfloat ret = 0;\n\tfloat pow = (float) Math.pow(10, roundToThisManyDecimalPoints);\n\tfl = fl * pow;\n\tfloat tmpFl = Math.round(fl);\n\tret = (float) tmpFl \/ pow;\n\treturn ret;\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This note provides a simple method for rounding a number to a specified number of decimal places in Java.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=130"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/130\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}