在 PowerShell 中添加数字 [英] Adding up numbers in PowerShell
本文介绍了在 PowerShell 中添加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 PowerShell 中将两个数字相加.我将用户提供的输入存储在 $Value1
和 $Value2
中.但是我找不到任何方法来实际将这些数字相加.我尝试使用 Measure-Object
cmdlet,但我似乎无法让它工作.
I am trying to add up two numbers in PowerShell. I have the input the user gives stored in $Value1
and $Value2
. However I can't find any way to actually add these numbers up. I tried using the Measure-Object
cmdlet but I can't seem to get it to work.
如何在 Powershell 中对数字进行加法/减法和乘法?
How does one add up/substract and multiply numbers in Powershell?
推荐答案
PS H:\> $value1 = 10
PS H:\> $value2 = 10
PS H:\> $value1 + $value2
20
如果您的数字存储为字符串,那么您需要将它们转换为整数,如下所示:
If your numbers are stored as strings then you'll need to cast them to integers like this:
PS H:\> $value1 = "10"
PS H:\> $value2 = "20"
PS H:\> [int]$value1 + [int]$value2
30
这篇关于在 PowerShell 中添加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文