1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| public string NumberConverted(double Number)
{
string integerLetter = "", decimalLetter = "", FormattedLetter = "";
int intergerValue = 0, decimalValue = 0;
char separateur = '.';
if(Number.ToString().Contains(','))
separateur=',';
String[] splits = Number.ToString().Split(separateur);
intergerValue = Convert.ToInt32(splits[0]);
if (splits.Length > 1) //get decimal value
{
string decimalPart = splits[1];
int partPrecision = 2;
string result = String.Empty;
if (partPrecision != decimalPart.Length)
{
int decimalPartLength = decimalPart.Length;
for (int i = 0; i < partPrecision - decimalPartLength; i++)
{
decimalPart += "0"; //Fix for 1 number after decimal ( 10.5 , 1442.2 , 375.4 )
}
result = String.Format("{0}.{1}", decimalPart.Substring(0, partPrecision), decimalPart.Substring(partPrecision, decimalPart.Length - partPrecision));
try
{
result = (Math.Round(Convert.ToDecimal(result))).ToString(); l'erreur est la result contient 40 avant le round mais au moment du rount il iffiche format chaine
incorrecte }
catch (Exception ex)
{
MessageBox.Show("Test sur poste client result round " + result, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Test sur poste client ex " + ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
result = decimalPart;
for (int i = 0; i < partPrecision - result.Length; i++)
{
result += "0";
}
MessageBox.Show("Test sur poste client decimalValue result" + decimalValue, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
decimalValue = Convert.ToInt32(result);
}
#region integerValue
if (intergerValue != 0)
{
integerLetter = convertir(intergerValue);
}
#endregion
#region decimalvalue
if (decimalValue != 0)
{
decimalLetter = convertir(decimalValue);
}
#endregion
if ((decimalValue != 0 && intergerValue != 0))
FormattedLetter = integerLetter + " Dirhams et " + decimalLetter + " Centimes";
if ((decimalValue == 0 && intergerValue != 0))
FormattedLetter = integerLetter + " Dirhams";
if ((decimalValue == 0 && intergerValue == 0))
FormattedLetter = "Zéro Dirhams";
if (FormattedLetter.StartsWith("un mille") || FormattedLetter.StartsWith("Un mille"))
FormattedLetter = FormattedLetter.Substring(3);
return FormattedLetter;
} |
Partager