Forum Discussion

Surya2023's avatar
Surya2023
Copper Contributor
Jun 30, 2022

Round to Specific Decimal Place not working

Hello Team,

Need a suggestion below script, infact  is working fine ,
********************   *********  **********  ***************  ************************
##Mention the path to search the files
$path = "c:\"
##Find out the files greater than equal to below mentioned size
$size = 100MB
##Limit the number of rows
$limit = 10
##Find out the specific extension file
$Extension = ""
##script to find out the files based on the above input
$largeSizefiles = get-ChildItem -path $path -recurse -ErrorAction "SilentlyContinue" -include $Extension | ? { $_.GetType().Name -eq "FileInfo" } | where-Object {$_.Length -gt $size} | sort-Object -property length -Descending | Select-Object Name, @{Name="SizeInGB";Expression={[math]::Round(($_.length /1GB),2)}},@{Name="Path";Expression={$_.directory}} -first $limit
$largeSizefiles |Export-Csv c:\IfilesizereportinNewGBs.txt


However you can see below output the FILE SIZE is like 2,57 and 2,47 ---> it should come like 2.57 and 2.47
Could you suggest where exactly the problem is ?


1 Reply

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    Surya2023 

     

    That suggests the locale within your PowerShell session isn't what you expect it to be.

     

    You can check the setting via either of the following commands and then cross-reference the returned codes with the default separator for that language. You'll probably find it's the comma rather than the period.

     

     

    # Example 1
    $Host.CurrentCulture;
    
    # Example 2
    Get-WinUserLanguageList;

     

     

    Edited to add information:

    Turns out I just learnt the PowerShell variable actually stores the exact result I was suggesting checking.

     

    # List the current decimal place separator.
    $Host.CurrentCulture.NumberFormat.CurrencyDecimalSeparator;

     

    Cheers,

    Lain

Resources