Im calculating the ratios of positive ints, negative ints and zeros in an array. I want to output the ratio rounded to six decimals.
using System;
namespace PlussMinussRatio
{
class MainClass
{
public static void Main(string[] args)
{
int[] array = new int[] { -4, 3, -9, 0, 4, 1 };
Solution(array);
}
public static void Solution(int[] arr)
{
float positive = 0, negative = 0, zero = 0;
float positiveRatio = 0, negativeRatio = 0, zeroRatio = 0;
float arrLength = arr.Length;
for(int i = 0;i < arrLength; i++)
{
if(arr[i] < 0)
{
negative++;
}
else if(arr[i] > 0)
{
positive++;
}
else
{
zero++;
}
}
positiveRatio = positive / arrLength;
negativeRatio = negative / arrLength;
zeroRatio = zero / arrLength;
Math.Round(positiveRatio, 6);
Math.Round(negativeRatio, 6);
Math.Round(zeroRatio, 6);
//Console.WriteLine(positive + " " + negative + " " + zero);
Console.WriteLine(positiveRatio + "\n" + negativeRatio + "\n" + zeroRatio);
}
}
}
This is what I get :
0.5 0.333333 0.166667 I want the 0.5 to be 0.500000.How can I do that?