{"id":4772,"date":"2021-03-24T16:24:07","date_gmt":"2021-03-24T15:24:07","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=4772"},"modified":"2022-07-25T08:31:51","modified_gmt":"2022-07-25T07:31:51","slug":"c-round-number-by","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-round-number-by\/","title":{"rendered":"C# \/ Typescript Round Number By"},"content":{"rendered":"\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"csharp\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">public static double RoundNumberUpBy(double number, double roundBy) => Math.Ceiling(number * 1.0 \/ roundBy) * roundBy; \/\/ Only add up\npublic static double RoundNumberBy(double number, double roundBy) => Math.Round(number * 1.0 \/ roundBy) * roundBy;\n\nvoid Main()\n{\n\tConsole.WriteLine(RoundNumberBy(0, 15));\n\tConsole.WriteLine(RoundNumberBy(1, 15));\n\tConsole.WriteLine(RoundNumberBy(20, 15));\n\tConsole.WriteLine(RoundNumberBy(25, 15));\n\tConsole.WriteLine(RoundNumberBy(35, 15));\n\tConsole.WriteLine(RoundNumberBy(40, 15));\n\tConsole.WriteLine(RoundNumberBy(55, 15));\n\tConsole.WriteLine(RoundNumberBy(65, 15));\n}\n\n\/*\nResults in:\n0\n0\n15\n30\n30\n45\n60\n60\n*\/\n<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Typescript<\/h2>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"typescript\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">export const roundNumberBy = (number: number, roundBy: number) => Math.round(number * 1.0 \/ roundBy) * roundBy;\nexport const roundNumberUpBy = (number: number, roundBy: number) => Math.ceil(number * 1.0 \/ roundBy) * roundBy;\n\nconst minutesToTime = (m: number) => `${String(Math.floor(m \/ 60)).padStart(2, \"0\")}:${String(m % 60).padStart(2, \"0\")}`;\n\nconst setNextHourTime = () => {\n\tvar now = new Date();\n\tvar startTimeInMinutes = (now.getHours() * 60) + now.getMinutes();\n\tstartTimeInMinutes = roundNumberBy(startTimeInMinutes, 15);\n\tvar endTimeInMinutes = startTimeInMinutes + 60;\n\n\tsetEventStart(minutesToTime(startTimeInMinutes));\n\tsetEventEnd(minutesToTime(endTimeInMinutes));\n};<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Typescript<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-4772","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=4772"}],"version-history":[{"count":6,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4772\/revisions"}],"predecessor-version":[{"id":6262,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4772\/revisions\/6262"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=4772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=4772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=4772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}