Windows Vista Forums

create my own class
  1. #1


    Arto Viitanen Guest

    create my own class

    I have a SQL Server query that returns some attributes. One of the
    attributes is of type float, so values look like 98.765432. I like
    to format it to contain only one decimal, like 98.8. I can do that
    with 98.765432.toString("##.#"), but I like to do this with



    $theResult | convertto-html > result.html

    pipeline. I tried to

    $theResult | { $_.percent = $_.percent.toString("##.#) } | ..

    but PowerShell said that $_ cannot be at the left side of the
    assignment.

    So I was thinging: if I create my own class that contains same
    properities as the query result, but the percent is already formatted.
    I could built the object, set its values and return it on the pipeline,
    right?

    BTW. This is only one of potential many similar queries, so there is
    no point on building the class on C# or other language.
    --
    Arto Viitanen, CSC Ltd.
    Espoo, Finland

      My System SpecsSystem Spec

  2. #2


    /\\/\\o\\/\\/ [MVP] Guest

    Re: create my own class

    You can use lelect-object to create a Custom object :

    PoSH>$result = 98.765432

    PoSH>$result | select @{e={$_.toString("##.#")};n='Percent'}

    Percent
    -------
    98.8

    (note you need to add $_.Percent, for testing I just made the variable the
    Number)

    Greetings /\/\o\/\/

    "Arto Viitanen" <arto.viitanen@csc.fi> wrote in message
    news:uq9CqiSFHHA.5000@TK2MSFTNGP03.phx.gbl...
    >I have a SQL Server query that returns some attributes. One of the
    > attributes is of type float, so values look like 98.765432. I like
    > to format it to contain only one decimal, like 98.8. I can do that
    > with 98.765432.toString("##.#"), but I like to do this with
    >
    > $theResult | convertto-html > result.html
    >
    > pipeline. I tried to
    >
    > $theResult | { $_.percent = $_.percent.toString("##.#) } | ..
    >
    > but PowerShell said that $_ cannot be at the left side of the
    > assignment.
    >
    > So I was thinging: if I create my own class that contains same
    > properities as the query result, but the percent is already formatted.
    > I could built the object, set its values and return it on the pipeline,
    > right?
    >
    > BTW. This is only one of potential many similar queries, so there is
    > no point on building the class on C# or other language.
    > --
    > Arto Viitanen, CSC Ltd.
    > Espoo, Finland



      My System SpecsSystem Spec

create my own class problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving from class C to class B ip address scheme, any tips(DC/DNS) markm75g Server General 1 14 Feb 2010
When a class is both an inherited class of another, and alsoimplements an interface method Curious .NET General 1 14 Aug 2009
create a class in a PowerShell script red_deer_hill PowerShell 5 28 Jun 2007
Create a class? Scott Swigart PowerShell 6 21 Mar 2007
How to Create Collection Generic Class using new-object TonyDesweet PowerShell 6 01 Jul 2006