I’m finding a way to to round-up, by using 2nd decimal to round-up the first decimal as shown in below table (needed value column).
I’ve tried below method and doesn’t really gives the desired value.
I am using custom logic to achieve (I got till 3.01 to 3.89). I wrote logic in C#. Let me add another condition for the series 3.9+ and lets see if it works.
I got the required output. But you have to implement the logic in UIPath because I wrote the logic in C# (tune the logic if you can) . Please let me know if you want code in C#.
double[] values = { 3, 3.01, 3.1, 3.11, 3.2, 3.29, 3.39, 3.90, 3.91, 3.99 };
foreach (double value in values)
{
//variable declaration
string finalvalue;
double finalvalue2;
//seperate strings if contains "."
if (value.ToString().Contains("."))
{
//split value into two parts by "."
string[] arr = value.ToString().Split('.');
//assign each part into one varvalue.ToString().Contains("."))iable
int value1 = Int32.Parse(arr[0]);
string val2 = arr[1];
//if the decimal part is like 3.01, 3.02... 3.99
//except 3.1,3.2.....
if(arr[1].Length > 1)
{
//parse string into Integer
finalvalue2 = Int32.Parse(arr[1]);
//divide the number by 10
finalvalue2 = finalvalue2 / 10;
//round the value to the nearest integer
finalvalue2 = (int)Math.Ceiling(finalvalue2);
//if decimal is like 3.91 tp 3.99
//increment the value1
//for example if number is 3.91 , increment 3 to 4
//and set value2 to zero
if(finalvalue2.ToString().Length > 1)
{
value1 = value1 + 1;
finalvalue2 = 0;
}
}
else
{
//if decimal is 3.1,3.2
//just consider the decimal part
finalvalue2 = Int32.Parse(arr[1]);
}
//display purpose
if(finalvalue2 == 0)
{
//if value2 is zero, just display the number without any decimals
finalvalue = value1.ToString();
}
else
{
//if value2 is not zero, display number with decimals
finalvalue = value1.ToString() + "." + finalvalue2.ToString();
}
}
else
{
//if value is 3,4,...
//just assign value to the final string
finalvalue = value.ToString();
}
//display final values in console window
Console.WriteLine("{0} --> {1}", value,
finalvalue);
}