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