{"id":1297,"date":"2011-01-12T22:40:38","date_gmt":"2011-01-12T22:40:38","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1297"},"modified":"2011-01-12T22:40:38","modified_gmt":"2011-01-12T22:40:38","slug":"adding-floats-together-with-commas-and-decimal-places","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2011\/01\/12\/adding-floats-together-with-commas-and-decimal-places\/","title":{"rendered":"Adding floats together with commas and decimal places"},"content":{"rendered":"<p>Someone contacted me about adding some numbers together with comma&#8217;s and dots within there values, here is the email via the contact me page.<\/p>\n<p>&#8220;Please I need a javascript code that can enable me add two or more numbers containing dot(.) and\/or comma (,) together. For example, 122.34 + 233.56. Or\/And 233,239.34 + 323,322.44. Thanks in advance.&#8221;<\/p>\n<p>Here is the code that will accomplish the request.<\/p>\n<pre lang=\"javascript\">\r\n<html>\r\n<script type=\"text\/javascript\" >\r\n       function load()\r\n       {\r\n               var value1=\"233,122.34\";\r\n               var value2=\"233.56\";\r\n               alert(parseFloat(value1.replace(\",\",\"\"))+parseFloat(value2.replace(\",\",\"\")));\r\n       }\r\n\r\n<\/script>\r\n<body onload=\"load()\">\r\n<\/body>\r\n<\/html>\r\n<\/pre>\n<p>The main part is the parseFloat and replacing the &#8220;,&#8221; with nothing &#8220;&#8221; to remove the none float characters via the object replace method.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone contacted me about adding some numbers together with comma&#8217;s and dots within there values, here is the email via the contact me page. &#8220;Please I need a javascript code that can enable me add two or more numbers containing dot(.) and\/or comma (,) together. For example, 122.34 + 233.56. Or\/And 233,239.34 + 323,322.44. Thanks &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2011\/01\/12\/adding-floats-together-with-commas-and-decimal-places\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Adding floats together with commas and decimal places<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[284,402,283],"class_list":["post-1297","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-adding-floating","tag-javascript","tag-question"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1297"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1297\/revisions"}],"predecessor-version":[{"id":1298,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1297\/revisions\/1298"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}