Rounding Up - C #

5

I use a program to correct my inventory of the sped tax file that I submit for revenue. But I'm in trouble because unitary products are coming out with broken value.

Example below, the product had (50) units after I step the program it gets broken value (13,089) I wanted to round up (note that I am dividing by 3.82)

|H010|7506195153574|UN|50|5,93|296,5|0|||001|296,5| (original)

|H010|7506195153574|UN|13,089|5,93|77,62|0|||001|296,5| (alterado)

My code:

string[] strArray = File.ReadAllLines(@"original.txt");
StreamWriter writer = File.AppendText(@"alterado.txt");
foreach (string str in strArray)
{
    string[] strArray2 = str.Split(new char[] { '|' });
    if (strArray2[1] == "H010")
    {
        strArray2[4] = Math.Round((decimal)((Convert.ToDecimal(strArray2[4]) / 382M) * 100M),3).ToString();
        string str2 = string.Join("|", strArray2);
        writer.WriteLine(str2);
    }
}
Just telling me I'm studying C # a little while ago and I'm going to start my course next year, I'm becoming a tutorial on the net, but I'm not understanding anything in the logic part. eur-lex.europa.eu eur-lex.europa.eu     
asked by anonymous 18.12.2015 / 19:24

1 answer

6

Use Math.Ceiling instead of Math.Round :

strArray2[4] = Math.Ceiling(Convert.ToDecimal(strArray2[4]) / 382M * 100M).ToString();

Ceiling always rounds up. Round rounds up only if the decimal part is greater than 0.5 .

    
18.12.2015 / 19:31