using System.Globalization;
public class NumberToWordsConverter
private static readonly string[] Units = { "", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín" };
private static readonly string[] PlaceValues = { "", "nghìn", "triệu", "tỷ", "nghìn tỷ", "triệu tỷ", "tỷ tỷ" };
public static string ConvertToWords(string amount, string currencyCode)
amount = amount.Replace(".", "").Replace(",", ".");
if (!decimal.TryParse(amount, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal number))
return "Số không hợp lệ";
long integerPart = (long)number;
int decimalPart = (int)((number - integerPart) * 100);
string words = ConvertIntegerToWords(integerPart);
string currencyText = currencyCode == "VNĐ" ? " đồng " : " đô la Mỹ";
words += " phẩy " + ConvertIntegerToWords(decimalPart) + currencyText;
words += " " + currencyText + "chẵn";
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(words);
private static string ConvertIntegerToWords(long number)
if (number == 0) return "không";
int chunk = (int)(number % 1000);
string chunkWords = ConvertChunkToWords(chunk);
words = chunkWords + " " + PlaceValues[place] + " " + words;
private static string ConvertChunkToWords(int number)
int hundreds = number / 100;
int tens = (number % 100) / 10;
words += Units[hundreds] + " trăm ";
if (tens == 0 && units > 0) words += "lẻ ";
words += Units[tens] + " mươi ";
if (units == 1) words += "mốt ";
else if (units > 0) words += Units[units] + " ";
if (units > 0) words += Units[units] + " ";
words += Units[units] + " ";
public static void Main()
string amountVND = "789.799";
string amountUSD = "123.456,78";
Console.WriteLine(ConvertToWords(amountVND, "VNĐ"));
Console.WriteLine(ConvertToWords(amountUSD, "USD"));