{"id":4024,"date":"2014-03-30T07:16:10","date_gmt":"2014-03-30T07:16:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-find-percentage-in-java-my-code-giving-error-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:16:10","modified_gmt":"2014-03-30T07:16:10","slug":"how-to-find-percentage-in-java-my-code-giving-error-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/how-to-find-percentage-in-java-my-code-giving-error-collection-of-common-programming-errors\/","title":{"rendered":"How to find Percentage in java my code giving error?-Collection of common programming errors"},"content":{"rendered":"<p>i am trying to get percentage but my code is giving &#8220;0.0&#8221; while both TotalMemory and Usage Memory have values i also set 4 decimal places, also but result is &#8220;0.0000&#8221; my code is,<\/p>\n<pre><code>private static long maxMemory=0;\nprivate static long freeMemory=0;\nprivate static long totalMemory=0;\nprivate static long usageMemory=0;\nprivate static double Percentage;\n\nRuntime runtime=Runtime.getRuntime();\nmaxMemory=runtime.maxMemory();\nfreeMemory=runtime.freeMemory();\ntotalMemory=runtime.totalMemory();\nusageMemory=totalMemory-freeMemory;\nPercentage=((usageMemory\/totalMemory)*100.0);\n\/\/NumberFormat percentage =NumberFormat.getPercentInstance();\n\/\/percentage = new DecimalFormat(\"0.0#%\");\n\/\/String pr = percentage.format(Percentage);\nSystem.out.print(Percentage);\nSystem.out.print(\"Total Memory:\"+totalMemory+\"\\n\");\nSystem.out.print(\"Memory Usage:\"+usageMemory+\"\\n\");\n<\/code><\/pre>\n<p>please help me what im doing wrong, any help in this regard is greatly appreciated.<\/p>\n<p>Thanks in advance !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>i am trying to get percentage but my code is giving &#8220;0.0&#8221; while both TotalMemory and Usage Memory have values i also set 4 decimal places, also but result is &#8220;0.0000&#8221; my code is, private static long maxMemory=0; private static long freeMemory=0; private static long totalMemory=0; private static long usageMemory=0; private static double Percentage; Runtime [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4024","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4024"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4024\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}