1

This is the table:

enter image description here

I use import-CSV to get the data from the table:

$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]
}

If I type Construction it will give me 0.1 as the value of Energy. But it cannot be used to do any calculation. For an example, if I use

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

What I got is 0.10.10.10.10.10.1. I don not want to just repeat the value for five times. I need 0.5 for the result. Is there any method to use this value as the normal variable (for normal calculations)?

1 Answer 1

2

It's treating it as a string instead of a floating point number. You'll need to cast it:

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

Or:

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

Or:

[double]$xx = $Energy[$Where]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.