public static string DecimalToLongString(Decimal valor, TiposMoedas moeda) { string[] moedaNome = { Moedas.GetNomeSingular(moeda).ToLower(), Moedas.GetNomePlural(moeda).ToLower() }; string[] centavoNome = { "centavo", "centavos" }; Decimal rounded = Decimal.Round(valor, 2); Int64 intero = Decimal.ToInt64(rounded); Int64 centavos = (Int64)(valor * 100) % 100; double logMil = (int)Math.Log(intero, 1000); bool incluiDe = (logMil >= 2 && (int)logMil == logMil); StringBuilder sb = new StringBuilder(); sb.Append(intero.ToLongString()); sb.Append(" "); if (incluiDe) { sb.Append("de "); } sb.Append(moedaNome[intero == 1 ? 0 : 1]); if (centavos > 0) { sb.Append(" e "); sb.Append(centavos.ToLongString()); sb.Append(" "); sb.Append(centavoNome[centavos == 1 ? 0 : 1]); } return(sb.ToString()); }
public static string GetNomePlural(TiposMoedas moeda) { return(NomePlural[(int)moeda]); }
public static string GetNomeSingular(TiposMoedas moeda) { return(NomeSingular[(int)moeda]); }
public static string GetSimbolo(TiposMoedas moeda) { return(NomeSimbolos[(int)moeda]); }
public static string ToLongString(this Decimal valor, TiposMoedas moeda) { return(DecimalToLongString(valor, moeda)); }