# Decimal Number Comparison

**URL:** <https://forums.powershell.org/t/decimal-number-comparison/21553>\
**Category:** PowerShell Help\
**Created:** [February 6, 2023, 3:19am UTC](https://forums.powershell.org/t/decimal-number-comparison/21553 "2023-02-06T03:19:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tlauwk](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tlauwk](https://forums.powershell.org/u/tlauwk)\
**Post date:** [February 6, 2023, 3:19am UTC](https://forums.powershell.org/t/decimal-number-comparison/21553/1 "2023-02-06T03:19:41Z")

</div>

Hi,

I’m retrieving directory sizes to 2 decimal places in GB:

```auto
$DirectoryGet = Get-ChildItem -Path $DirectoryPath -Recurse
$DirectorySize = [Math]::Round((($DirectoryGet | Measure-Object -Property Length -Sum).Sum /1GB),2)

```

Then grouping them into:

```auto
If ($DirectorySize -lt 1)
{
    <do something with directories under 1GB>
}
Else
{
    <do something with directories greater than or equal to 1GB>
}

```

$DirectorySize.GetType() is a [double]. I’ve also tried it with [float] and [decimal] and all 3 seems to work in the if statement.

Is the above comparison actually comparing decimal numbers (eg $DirectorySize 0.23 \< 1 or $DirectorySize 1.54 \>= 1)?

Or is it just comparing the integer component of $DirectorySize left of the dot and ignoring everything right of the dot?

Thanks.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [February 6, 2023, 8:51am UTC](https://forums.powershell.org/t/decimal-number-comparison/21553/2 "2023-02-06T08:51:29Z")

</div>

> [@tlauwk](#):
>
> Is the above comparison actually comparing decimal numbers (eg $DirectorySize 0.23 \< 1 or $DirectorySize 1.54 \>= 1)?
> 
> Or is it just comparing the integer component of $DirectorySize left of the dot and ignoring everything right of the dot?

Would it make any difference in your case actually? 🤷🏽‍♂️ 😏

Regardless of that … do you have any reason to doubt? You mentioned that it works as expected? What’s your issue? 🤔

And BTW:

> [@tlauwk](#):
>
> I’m retrieving directory sizes to 2 decimal places in GB:

Since you compare against an integer anyway one decimal point would have been enough though.

---

<div class="post-metadata">

**Author:** ![tlauwk](https://avatars.discourse-cdn.com/v4/letter/t/96bed5/32.png) [@tlauwk](https://forums.powershell.org/u/tlauwk)\
**Post date:** [February 7, 2023, 12:29am UTC](https://forums.powershell.org/t/decimal-number-comparison/21553/3 "2023-02-07T00:29:53Z")

</div>

No issue. Just curious … for a deeper dive into mechanics of floating point comparison in powershell.

Code was just an ad hoc example. Google-fu brought up more questions than answers for me so thought I’ll tap the expertise over here.

Thanks.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:15pm UTC](https://forums.powershell.org/t/decimal-number-comparison/21553/4 "2024-05-16T20:15:12Z")

</div>

Closed on May 16, 2024, 8:15pm UTC


