I've been trying to find best way to convert decimal/string to currency depending on my choice.
public static string returnWaluta(string varS, string varSymbol) {
decimal varD = decimal.Parse(varS);
if (varSymbol == "EUR") {
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR", false);
return String.Format("{0:c}", varD);
} else if (varSymbol == "PLN") {
Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL", false);
return String.Format("{0:c}", varD);
} else if (varSymbol == "USD") {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
return String.Format("{0:c}", varD);
} else {
// Not handled currency
MessageBox.Show(varSymbol);
return varS.ToString();
}
}
public static string returnWaluta(decimal varS, string varSymbol) {
if (varSymbol == "EUR") {
Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR", false);
return String.Format("{0:c}", varS);
} else if (varSymbol == "PLN") {
Thread.CurrentThread.CurrentCulture = new CultureInfo("pl-PL", false);
return String.Format("{0:c}", varS);
} else if (varSymbol == "USD") {
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
return String.Format("{0:c}", varS);
} else {
// Not handled currency
MessageBox.Show(varSymbol);
return varS.ToString();
}
}
Is this good aproach or i could do this better? I get data from SQL database. I get decimal value and currency it is on (like EUR, USD, PLN). This seems to work but maybe there's better option? Also for now this is single threaded aplication, am i making global change when i change Thread.CurrentThread.CurrentCulture or is it just temporary until i return from the method?
With regards,
MadBoy
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…