【发布时间】:2020-07-29 14:29:21
【问题描述】:
我正在尝试创建一个定价函数,该函数采用 usd 价格和 eur 价格并进行一些计算。但是,在尝试运行它时出现以下错误:
方法调用失败,因为 [System.Object[]] 不包含名为“op_Division”的方法。 在 line:11 char:5
代码:
function Get-Pricing($USD, $EUR) {
[hashtable]$Return = @{}
$USDGBP = [math]::Round((Invoke-RestMethod "https://api.exchangeratesapi.io/latest?base=USD").rates.GBP,2)
$EURGBP = [math]::Round((Invoke-RestMethod "https://api.exchangeratesapi.io/latest?base=EUR").rates.GBP,2)
$USDEx = ($USD * $USDGBP)
$EUREx = ($EUR * $EURGBP)
$ReturnedPrice = ((( $EUREx + 0.25 ) * 0.32 ) + $EUREx )
$PriceIndex = (((( $USDEx / $ReturnedPrice ) * 0.5 ) + (( $EUREx / $ReturnedPrice ) * 1.5 ) + 1 ) / 3)
$PriceCM = (( $ReturnedPrice / $EUREx ) * $PriceIndex )
$Return.PriceIndex = $PriceIndex
$Return.PriceCM = $PriceCM
Return $Return
}
[float]$a = 23.83
[float]$b = 16.11
Write-Host $a -ForegroundColor Red
Write-Host $b -ForegroundColor Red
$Pricing = Get-Pricing($a, $b)
Write-Host "A: "$Pricing.PriceIndex -ForegroundColor Cyan
Write-Host "B: "$Pricing.PriceCM -ForegroundColor Cyan
【问题讨论】:
-
Get-Pricing($a, $b)->Get-Pricing -a $a -b $b -
成功了,谢谢
标签: powershell