Skip to content

Instantly share code, notes, and snippets.

@javierguerrero
Created March 8, 2017 20:40
Show Gist options
  • Save javierguerrero/0fb74a7fef57c3e12fc9ce0e0cb67267 to your computer and use it in GitHub Desktop.
Save javierguerrero/0fb74a7fef57c3e12fc9ce0e0cb67267 to your computer and use it in GitHub Desktop.
private decimal ConvertStringNumberToDecimal(string importTransac)
{
CultureInfo enUS = new CultureInfo("en-US");
CultureInfo esAR = new CultureInfo("es-AR");
CultureInfo originalCulture = CultureInfo.CurrentCulture;
decimal importe;
decimal parse;
System.Threading.Thread.CurrentThread.CurrentCulture = enUS;
if (decimal.TryParse(importTransac, out parse) == true)
{
importe = decimal.Parse(importTransac);
}
else
{
System.Threading.Thread.CurrentThread.CurrentCulture = esAR;
importe = decimal.Parse(importTransac);
}
System.Threading.Thread.CurrentThread.CurrentCulture = originalCulture;
return importe;
}
//importTransac = "11.748,00";
//importTransac = "11,748.00";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment