{"id":8831,"date":"2007-01-09T12:34:00","date_gmt":"2007-01-09T12:34:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/01\/09\/2-2-equals-monday-evening\/"},"modified":"2019-02-18T13:20:54","modified_gmt":"2019-02-18T20:20:54","slug":"2-2-equals-monday-evening","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/2-2-equals-monday-evening\/","title":{"rendered":"2 + 2 equals &#034;Monday Evening&#034;"},"content":{"rendered":"<p>I wanted to follow up on Jeffrey&#8217;s post and one of the comments.&nbsp; It has to do with this example:<\/p>\n<p><code>PS&gt; [int]1\/2<br \/>0.5 <\/code><\/p>\n<p>The reason that we get a double rather than an int is because of precedence.&nbsp; The conversion has a higher precedence than the division operation, so what<\/p>\n<p><code>[int]1\/2<\/code><\/p>\n<p><em>really<\/em> means is:<\/p>\n<p>&#8220;Convert 1 to an integer and then divide by 2&#8221;, which will result in a double (0.5).&nbsp; If we really want our results to be an integer, we should do the following:<\/p>\n<p><code>[int](1\/2)<\/code><\/p>\n<p>which <em>first<\/em> does the division and <em>then<\/em> converts to an integer.&nbsp; Viola, we get what we want!<\/p>\n<p><code>PS&gt; [int](1\/2)<br \/>0 <\/code><\/p>\n<p>Jim Truher [MSFT]<br \/>Windows PowerShell Program Manager<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to follow up on Jeffrey&#8217;s post and one of the comments.&nbsp; It has to do with this example: PS&gt; [int]1\/20.5 The reason that we get a double rather than an int is because of precedence.&nbsp; The conversion has a higher precedence than the division operation, so what [int]1\/2 really means is: &#8220;Convert 1 [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8831","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>I wanted to follow up on Jeffrey&#8217;s post and one of the comments.&nbsp; It has to do with this example: PS&gt; [int]1\/20.5 The reason that we get a double rather than an int is because of precedence.&nbsp; The conversion has a higher precedence than the division operation, so what [int]1\/2 really means is: &#8220;Convert 1 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=8831"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8831\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=8831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}