2015-08-29 205 views
1

這是表:如何將輸出轉換爲變量?

enter image description here

我用import-CSV從表中獲取數據:

$Process = @() 
$Energy = @() 

Import-Csv C:\Users\Shuai\Desktop\test\Test.csv |` 
ForEach-Object 
{ 
    $Process += $_."Process" 
    $Energy += $_.Energy 
} 

$inputName = Read-Host -Prompt "Process" 

if ($Process -contains $inputName) 
{ 
    $Where = [array]::IndexOf($Process, $inputName) 
    $Energy[$Where] 
} 

如果鍵入Construction它會給我0.1爲Energy值。但它不能用來做任何計算。 舉一個例子,如果我用

$xx = $Energy[$Where] 
$XY = $xx * 5 

我得到了什麼是0.10.10.10.10.10.1。我不想只重複五次價值。我需要0.5的結果。 是否有任何方法使用此值作爲正常變量(用於正常計算)?

回答

2

它將其視爲字符串而不是浮點數。你需要將其強制轉換:

$xx = $Energy[$Where] -as [double] 

或者:

$xx = [double]$Energy[$Where] 

或者:

[double]$xx = $Energy[$Where] 
+0

很不錯的!謝謝你,小夥伴!!! – rock

相關問題