Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Adding in PowerShell

Reply
 
Old 01-07-2008   #1 (permalink)
NeilOz


 
 

Adding in PowerShell

I know this is going to be simple.. but say I have a $Sum = 10 and I want
$Total = $Sum+.10
I've also tried $Total = ($Sum + .10) and Ive tried $diff = .10 with $Total
= ($Sum + $Diff) without success..

What did I do wrong?

My System SpecsSystem Spec
Old 01-07-2008   #2 (permalink)
Mark E. Schill


 
 

Re: Adding in PowerShell

This works for me.

PS> $Sum = 10
PS> $Total = $Sum + .10
PS> $Total
10.1

Are you getting an error message?



NeilOz wrote:
Quote:

> I know this is going to be simple.. but say I have a $Sum = 10 and I want
> $Total = $Sum+.10
> I've also tried $Total = ($Sum + .10) and Ive tried $diff = .10 with $Total
> = ($Sum + $Diff) without success..
>
> What did I do wrong?
My System SpecsSystem Spec
Old 01-07-2008   #3 (permalink)
NeilOz


 
 

Re: Adding in PowerShell

Nope no error message, What I'm doing is downloading the results from a web
service into an xml string using

[xml]$Quote =
$Webclient.DownloadString("http://server:1891/MarketInfoService.asmx/LiveQuote?Code="+$StockCode)

$BestBuy = $Quote.Quote.BestSellPrice

I get the desired result from $BestBuy which is say 10.00
But when I run $BuyPrice = $BestBuy + .10
I get $BuyPrice = 10.00.10

"Mark E. Schill" wrote:
Quote:

> This works for me.
>
> PS> $Sum = 10
> PS> $Total = $Sum + .10
> PS> $Total
> 10.1
>
> Are you getting an error message?
>
>
>
> NeilOz wrote:
Quote:

> > I know this is going to be simple.. but say I have a $Sum = 10 and I want
> > $Total = $Sum+.10
> > I've also tried $Total = ($Sum + .10) and Ive tried $diff = .10 with $Total
> > = ($Sum + $Diff) without success..
> >
> > What did I do wrong?
>
My System SpecsSystem Spec
Old 01-08-2008   #4 (permalink)
Kirk Munro [MVP]


 
 

Re: Adding in PowerShell

That's because $BestBuy is a string, so PowerShell is performing string
concatenation when you use it with the + operator. To get a numeric value
you need to typecast $BestBuy (e.g $BuyPrice = [double]$BestBuy + .10).

--
Kirk Munro [MVP]
Poshoholic
http://poshoholic.com


"NeilOz" <NeilOz@xxxxxx> wrote in message
newsCC78F21-CE95-4C34-B522-A423FCA6CD2C@xxxxxx
Quote:

> Nope no error message, What I'm doing is downloading the results from a
> web
> service into an xml string using
>
> [xml]$Quote =
> $Webclient.DownloadString("http://server:1891/MarketInfoService.asmx/LiveQuote?Code="+$StockCode)
>
> $BestBuy = $Quote.Quote.BestSellPrice
>
> I get the desired result from $BestBuy which is say 10.00
> But when I run $BuyPrice = $BestBuy + .10
> I get $BuyPrice = 10.00.10
>
> "Mark E. Schill" wrote:
>
Quote:

>> This works for me.
>>
>> PS> $Sum = 10
>> PS> $Total = $Sum + .10
>> PS> $Total
>> 10.1
>>
>> Are you getting an error message?
>>
>>
>>
>> NeilOz wrote:
Quote:

>> > I know this is going to be simple.. but say I have a $Sum = 10 and I
>> > want
>> > $Total = $Sum+.10
>> > I've also tried $Total = ($Sum + .10) and Ive tried $diff = .10 with
>> > $Total
>> > = ($Sum + $Diff) without success..
>> >
>> > What did I do wrong?
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
PowerShell - adding security group PowerShell
PowerShell Leaders Join Forces and offer a pre-release version of PowerShell for 50% off the retail value PowerShell
Info: Adding books to Powershell Site PowerShell
Adding Promise FastTrack 378 Adding Vista hardware & devices
Adding Promise FastTrack 378 Adding Vista hardware & devices


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46