{"id":287,"date":"2013-04-30T21:16:31","date_gmt":"2013-04-30T21:16:31","guid":{"rendered":"http:\/\/www.webninjataylor.com\/library\/?p=287"},"modified":"2014-06-24T21:26:01","modified_gmt":"2014-06-24T21:26:01","slug":"decimals-in-javascript","status":"publish","type":"post","link":"https:\/\/webninjataylor.com\/library\/decimals-in-javascript\/","title":{"rendered":"Decimals in JavaScript"},"content":{"rendered":"<p><strong>Use decimals cautiously <\/strong>because\u00a0JavaScript uses Binary Floating Point numbers, so 0.1 + 0.2 =\u00a00.30000000000000004. To get around this issue, you can multiply your numbers to remove the decimal portion.<\/p>\n<pre>var hamburger = 8.20;\r\nvar fries = 2.10;\r\nvar total = hamburger + fries;\r\nconsole.log(total); \/\/Outputs 10.299999999999999\r\n\r\nhamburger = hamburger * 100;\r\nfries = fries * 100;\r\ntotal = hamburger + fries;\r\ntotal = total \/ 100;\r\nconsole.log(total); \/\/Outputs 10.3\r\n<\/pre>\n<h2>Resources<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.codeproject.com\/Articles\/580165\/JavaScript-Best-Practices?utm_source=javascriptweekly&amp;utm_medium=email\" target=\"_blank\">JavaScript Best Practices, Tim Corey (4\/30\/2013)<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Use decimals cautiously because\u00a0JavaScript uses Binary Floating Point numbers, so 0.1 + 0.2 =\u00a00.30000000000000004. To get around this issue, you can multiply your numbers to remove the decimal portion. var hamburger = 8.20; var fries = 2.10; var total = hamburger + fries; console.log(total); \/\/Outputs 10.299999999999999 hamburger = hamburger * 100; fries = fries * [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[144],"tags":[9],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-web-shots","tag-javascript"],"_links":{"self":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":9,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"predecessor-version":[{"id":3373,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/posts\/287\/revisions\/3373"}],"wp:attachment":[{"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webninjataylor.com\/library\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}