How do I convert the number "1,00" to "100" in .Net?
Clarification: I have this code:
VALOR = order.Total.T开发者_开发百科oString("#0.00");
It returns the text "1,00" but I need "100" (without comma).
string str = Decimal.Parse("1,00", NumberStyles.Currency).ToString();
This handles currency strings in a generic way. See the NumberStyles for specifics and other options.
Update: Based on updated comments it sounds like your current culture is the issue. Try something like this:
string str = orderTotal.ToString("#0.00", new CultureInfo("en-US", false));
"1,00".ToString().Replace(",", "");
Replace "1,00" with whatever you're converting. This will work for currencies (in specific localizations only) and any other data type that supports ToString() in a logical manner.
If 1,00 is decimal, probably you're in a culture like Spanish (Spain) where decimal separator is ',' and thousands separator is '.' then:
VALOR = (order.Total * 100).ToString("N0");
Multiply by 100 and round with a precision of 0?
Just URL encode it as it is. Then URL decode when it will be consumed.
VALOR = HttpUtility.UrlEncode(VALOR);
You mentioned in comments on your question that you need to remove the comma because you are passing the value in a URL. I interpreted this to mean that because commas aren't valid in urls, you just need to remove the comma for the value to pass correctly - not because you need to change the locale formatting or otherwise change the data in any way.
If that is the case, then you don't need to alter the string at all - you can simply encode it.
精彩评论