this is function to format text that contains numbers only into $ currency
private String GLOBALIZE_TEXT(String originalText)
{
decimal parsed;
CultureInfo myCultureInfo;
string formattedText = "";
//use try catch to prevent larger inputs
try
{
parsed = decimal.Parse(originalText, CultureInfo.InvariantCulture);
myCultureInfo = new CultureInfo("$");
formattedText = string.Format(myCultureInfo, "{0:c}", parsed);
}
catch (Exception ignorethis)
{
}
return formattedText;
}
now in usage:
String myString = "3821";
myString = GLOBALIZE_TEXT(myString);
//now my String becomes "$3,821.00"
question is, can I parse back that “$3,821.00” to “3821” again?
I need to parse it back so I can use it as an integer where “3821” can be converted by Convert.ToInt32("3821").
or maybe that parsed String can also be converted directly to string?
Please let me know your opinion.
You can try:
More information on the
NumberStylesenum can be found on MSDN here and more information on this specificdouble.Parsemethod can be found on MSDN here.