I’m trying to round off the following values, but I don’t know what’s wrong.
NewValue -=(System.Math.Round(Global.WorkData.ValueOld - System.Math.Round (Global.WorkData.ValueOld * 20, 0) / 20, 2 ));
And this is what I did:
NewValue -=(System.Math.Round(Global.WorkData.ValueOld, 2, MidpointRounding.AwayFromZero - System.Math.Round(Global.WorkData.ValueOld * 20, 2,MidpointRounding.AwayFromZero) / 20, 2 ));
Could you please tell me what’s wrong in my code? why I can’t compile it?
Thanks
You’ve got at least one bracketing error, so it’s trying to subtract a decimal value from a
MidpointRounding.However, I still can’t work out what you’re really trying to do.
I strongly recommend that you split this statement up – split the calls to
Round, and then one using the values. For example:I still can’t work out exactly what you want to do with the results – what’s the 2 at the end of the statement meant to be for? What is the first statement in your question meant to be? Maybe you want:
? That might be it, but I really don’t know…
Shorter statements make the code clearer and let you find this kind of error much more easily.