2015-10-14 66 views
0

我想在貨幣格式的開頭沒有「$」格式化貨幣。

我該怎麼做?我試過,但它不工作:

Format(e.Row.Cells(7).Text, "{0:n}") 

我知道$的1,234是:

Format(e.Row.Cells(7).Text, "Currency") 

但我試圖刪除

$

在貨幣前面。

+0

如果你不希望的貨幣,不使用貨幣格式。使用數字格式。 – GSerg

+0

VS中有一個設置,根據您想要顯示的內容更改貨幣符號。如果你什麼都不需要,那就用'Integer'或者'Decimal/Double' – MAC

+0

[格式化一個像貨幣但沒有貨幣符號(C#)的雙值的可能的重複](http://stackoverflow.com/questions/1048643)/format-a-double-value-like-currency-but-without-the-currency-sign-c)http://stackoverflow.com/a/1048669/1316573 –

回答

0
Dim value As Double = e.Row.Cells(7).Text 
Dim val2 As String 
val2 = (value.ToString("#,#", CultureInfo.InvariantCulture)) 
e.Row.Cells(7).Text = String.Format(CultureInfo.InvariantCulture, "{0:#,#}", val2) 

不要忘了Imports System.Globalization

0

TrimStart()功能

Dim strVal As String = "$1,234" 
strVal = strVal.TrimStart("$") 

replace()功能

Dim strVal As String = "$1,234" 
strVal = strVal.Replace("$",String.Empty) 

你可以使用這樣

e.Row.Cells(7).Text = e.Row.Cells(7).Text.TrimStart("$") 

e.Row.Cells(7).Text = e.Row.Cells(7).Text.Replace("$",String.Empty)