{"id":14750,"date":"2024-06-07T21:54:09","date_gmt":"2024-06-07T18:54:09","guid":{"rendered":"https:\/\/elzero.org\/?p=14750"},"modified":"2024-06-07T21:54:09","modified_gmt":"2024-06-07T18:54:09","slug":"implement-functions-with-cpp-money-format","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/implement-functions-with-cpp-money-format\/","title":{"rendered":"Money Format"},"content":{"rendered":"<h3>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-c\">\r\n#include <iostream>\r\n#include <string>\r\nusing namespace std;\r\n\r\n\/*\r\n  Money Format\r\n  100 -> 100\r\n  1000 -> 1,000\r\n  100000 -> 100,000\r\n  1000000 -> 1,000,000\r\n*\/\r\n\r\nstring moneyFormat(int n)\r\n{\r\n  string snum = to_string(n); \/\/ 100000\r\n  string result;\r\n  int count = 0;\r\n  for (int i = snum.size() - 1; i >= 0; i--) \/\/ [1]00000\r\n  {\r\n    result = snum[i] + result; \/\/ i = 0\r\n    \/\/ [Loop 1] 0 + \"\"\r\n    \/\/ [Loop 2] 0 + 0 + \"\"\r\n    \/\/ [Loop 3] 0 + 0 + 0 + \"\"\r\n    \/\/ [Loop 3] , + 0 + 0 + 0 + \"\"\r\n    \/\/ [Loop 4] 0 + , + 0 + 0 + 0 + \"\"\r\n    \/\/ [Loop 5] 0 + 0 + , + 0 + 0 + 0 + \"\"\r\n    \/\/ [Loop 6] 1 + 0 + 0 + , + 0 + 0 + 0 + \"\"\r\n    \/\/ Last Result -> 100,000\r\n\r\n    count++; \/\/ 6\r\n    if (count % 3 == 0 && i != 0)\r\n    {\r\n      result = \",\" + result;\r\n    }\r\n  }\r\n  return result;\r\n}\r\n\r\nint main()\r\n{\r\n  cout << moneyFormat(100) << endl;\r\n  cout << moneyFormat(1000) << endl;\r\n  cout << moneyFormat(10000) << endl;\r\n  cout << moneyFormat(100000) << endl;\r\n  cout << moneyFormat(1000000) << endl;\r\n  cout << moneyFormat(10000000) << endl;\r\n  cout << moneyFormat(100000000) << endl;\r\n  cout << moneyFormat(1000000000) << endl;\r\n  return 0;\r\n}\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0645\u062d\u062a\u0648\u0649 \u0627\u0644\u062f\u0631\u0633<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1454],"tags":[],"class_list":["post-14750","post","type-post","status-publish","format-standard","hentry","category-implement-functions-with-cpp"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14750","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=14750"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14750\/revisions"}],"predecessor-version":[{"id":14751,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/14750\/revisions\/14751"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=14750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=14750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=14750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}