Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Powershell的.TypeText中使用区域性函数_Powershell_Formatting_Numbers - Fatal编程技术网

在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 €

工作起来很有魅力!多谢各位!