locked
Alternatives to (Measure-Object -sum).Sum RRS feed

  • Question

  • I'm stuck in the following situation: I have to get information out of a csv file. I imported the csv using import-csv. My raw data looks like this:

    45227;01.10.2018 03:24:00;Xxxx Xxxx Xxxxx x XX xxxxxxxxxxxxxx Xxxxx xxxxxxxxxxxxxxxxxxxxx;;3;XXXX;XXXX;XXX@XX.com;;;3.7;;
    

    Whereas the "3.7"-Line contains my important information ("Points"). Here comes my first problem --> Using import-csv, powershell will save this information in a "string" property. To avoid that i used the following line:

    | Select @{Name="Points";Expression={[decimal]$_.Points}}
    

    Now i'm having my Selected.System.Management.Automation.PSCustomObject containing that property System.Decimal. Now i wanted to sum up all the points, that were used by the same e-mail address:

    $Data[$Index].Points += ($Imported_CSV | where {$_.Sender -eq $Imported_CSV_Unique.Sender} | measure Points -sum).Sum
    

    This seemed to work just fine, but if i open up $Data[$Index] | gmi'm getting this: Points NoteProperty double Points=71301.6000000006

    It seems like i'm producing an overflow of "double", because the number being displayed is totally wrong. I want to stick to decimal or integer so i have an output like 71123.4 or something like that.

    The property changed to "double". I digged a bit and i found out that Powershell's GenericMeasureInfo.SumProperty can only give back a "Nullable <Double>"as property value.

    Is there any other approach for that, so i don't have to use (Measure-Object -sum).Sum?

    Thanks in advance!


    • Edited by Urs68 Sunday, March 17, 2019 10:07 AM
    • Moved by Bill_Stewart Wednesday, September 4, 2019 6:40 PM Abandoned
    Sunday, March 17, 2019 9:59 AM

All replies

  • I have to admit that I don't really understand your problem. Is it possible that you provide some example data and a relevant part of the code you're using? I'd like to reproduce the behaviour you're talking about to fully understand it. At StackOverflow they call it: "How to create a Minimal, Complete, and Verifiable example".

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Sunday, March 17, 2019 6:36 PM