[英]How to change the culture of a number in C#?
我正在向paypal發送參數作為隱藏形式的變量。
但我的網站文化是丹麥語。 所以“50,00”是“amount_1”的值
<input type="hidden" name="amount_1" value="50,00" />
我正在使用此代碼將50轉換為“50,00”
item.PricePaid.ToString("#.00")
我相信這個數字應該是這樣的:“1234.56”有沒有辦法在這個過程中將文化設置為en-US? (不是寬邊)還是更好的方法呢?
謝謝!
您可以使用帶有IFormatProvider
的ToString
重載,然后使用GetCultureInfo
傳遞所需的區域性信息:
item.PricePaid.ToString("#.00", CultureInfo.GetCultureInfo("en-US"));
或者,您可以(可能)指定不變文化而不是“en-US”:
item.PricePaid.ToString("#.00", CultureInfo.InvarianCulture);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.