I have basically four numbers (say 100, 200, 300, 400), and I need to calculate the probability as 100/(100+200+300+400), 200/(100+200+300+400), and so on.
When I use the decimal data type to store these probabilities, they don't up to one due to round issues. What's the best way to past this without making the probabilities too inaccurate? Basically I do this calculation many many times, so I don't want to have to change all the divisions into Math.Round stuff. :|
decimial? That should be exact asdecimal.... You aren't perhaps usingdouble, or using a literal such as1.0(which should be1.0Mto meandecimal) - Marc Gravellprobabilities[i, j] = ((decimal)Count[i, j]) / ((decimal)(NUMBER_OF_TIMESTEPS - numberOfTimestepsToSkip));The double array probabilities is decimal type. - Matt