{"id":216,"date":"2010-06-04T14:41:34","date_gmt":"2010-06-04T18:41:34","guid":{"rendered":"http:\/\/erics-test-lab.com\/?p=216"},"modified":"2010-06-04T14:41:34","modified_gmt":"2010-06-04T18:41:34","slug":"penny-rounding","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2010\/06\/penny-rounding\/","title":{"rendered":"Penny Rounding"},"content":{"rendered":"<p>Rounding issues are the bane of every accountants existence. While a few records may only produce a few cents difference a few million records can lead to thousands of dollars or just a penny. Depending on if the rounding occurs at the detail level or the summary level you can get very different results. We coders can also make poor decisions which impact or minimize the error. Assume we have 100 records at 249.754988 after applying a currency conversion. So our true total should be $24975.4988<br \/>\n<!--more--><br \/>\n<code>select convert(numeric(20,2), <strong>round(sum(amt),2<\/strong>)) as amt<\/code><br \/>\nThis bit of code at a Summary level would give us a grand total of $24975.50  (.0012 overstated)<br \/>\nIf however we had used the round function at the detail  level we would have a mere $24975.00 (.4912 understated)<\/p>\n<p><code>select convert(numeric(20,2),<strong>sum(amt)<\/strong>) as amt<\/code><br \/>\nAt the summary level we are now losing the decimals beyond the first two through truncation so our grand total is $24975.49<br \/>\nThe detailed level would be the same as above. <\/p>\n<p>Imagine if the value was for 1Million records rather than 100 records. The difference would be $4988.00 less than it should be. Still a small percentage, but compounding rounding errors could be even more detrimental. If you must round for formatting, try to do so at a summary level.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rounding issues are the bane of every accountants existence. While a few records may only produce a few cents difference a few million records can lead to thousands of dollars or just a penny. Depending on if the rounding occurs &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2010\/06\/penny-rounding\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,24,14],"tags":[],"class_list":["post-216","post","type-post","status-publish","format-standard","hentry","category-code","category-snippets-quick-code-tips-for-single-elements-attributes-or-details","category-sql"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":0,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}