Assuming myDecimal is System.Decimal , then Math.Round(myDecimal, 2).ToString(); will display two decimal digits of precision, as you wish, without any format string (unless the absolute value of your number is greater than 10 ^ 27-1). This is because the decimal data type preserves the full precision of the number. That is, 1m , 1.0m and 1.00m are stored differently and will be displayed differently.
Note that this does not apply to float or double . 1f , 1.0f and 1.00f are saved and displayed the same way as 1d , 1.0d and 1.00d .
Since the format string should be parsed at runtime, I would probably omit it in most cases for code like this.
source share