在Powershell的.TypeText中使用区域性函数
我想得到像在Powershell的.TypeText中使用区域性函数,powershell,formatting,numbers,Powershell,Formatting,Numbers,我想得到像1039,00(逗号是十进制分隔符)这样的数字。 但现在我得到了1039.00 这件事就在代码中: $selection.TypeText("Angebotspreis: Using-Culture de-de {$TotalPrice} Euro ") 我试着这样做: $selection.TypeText("Angebotspreis: $(Using-Culture de-de {$TotalPrice}) Euro ") $selection.TypeText("Ange
1039,00
(逗号是十进制分隔符)这样的数字。
但现在我得到了1039.00
这件事就在代码中:
$selection.TypeText("Angebotspreis: Using-Culture de-de {$TotalPrice} Euro ")
我试着这样做:
$selection.TypeText("Angebotspreis: $(Using-Culture de-de {$TotalPrice}) Euro ")
$selection.TypeText("Angebotspreis: @"Using-Culture de-de {$TotalPrice}"@ Euro ")
等等
使用文化功能是:
Function Using-Culture (
[System.Globalization.CultureInfo]$culture = (throw “USAGE: Using-Culture - Culture culture -Script {scriptblock}”),
[ScriptBlock]$script= (throw “USAGE: Using-Culture -Culture culture -Script {scriptblock}”))
{
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
trap
{
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
Invoke-Command $script
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
此外,在控制台中:
PS C:\Users\alexz> $(Using-Culture de-de {$TotalPrice})
7908.90
但是
我怎样才能修好它 可能您正在寻找
double
上的重载ToString
方法,您可以为浮点(十进制)值传递f
和CultureInfo
例如:
$ammount = 7908.39
$ammount.ToString('f', (New-Object System.Globalization.CultureInfo("de-DE")))
输出:
7908,39
7.908,39 €
或者,如果您希望使用
€
符号和点表示千位,请使用c
表示货币:
$ammount = 7908.39
$ammount.ToString('c', (New-Object System.Globalization.CultureInfo("de-DE")))
输出:
7908,39
7.908,39 €
工作起来很有魅力!多谢各位!