How the value is output will depend on the actual value.
While Math.Round(value, 2)
will round the value to two decimal places, if that rounded value is 1.00 or 1.50 (for example) it will be displayed as "1" or "1.5" as the trailing zeros are omitted by default.
If you want to display the value to 2 decimal places then there are a number of ways to do this. All require you to call either string.Format
or explicitly call .ToString
with a format parameter.
One is to use:
MessageBox.Show(String.Format("{0:0.00}", value));
The first "0" represents the number itself and the the "0.00" indicates to the formatting engine that this is a floating point number with two decimal places. You can use "#:##" instead.
Source
Another is:
MessageBox.Show(value.ToString("F"));
Which is the fixed point format specifier. Adding a number specifies the number of decimal places (2 is the default). Source
Given that you say of your code that "This works fine." then your verification step is correct. You are checking that the value is a number and that the value rounded to 2 decimal places is the value you want. There's nothing more you need to do.