1

I have a small question regarding Math.Round function. I need the string "12.123456" to be rounded at 4 decimals. I used:

 Math.Round(Convert.ToDouble(pData), 4).ToString()

where pData is defined as string, but the values are decimal with 7 decimals. My problem is that I expected to get every time the exact 4 decimals, but for some values it gives me only 2 (eg. 12.12 instead of 12.1200). How can I change in order to always get the needed 4 decimals? Regards,

BogdanM
  • 957
  • 4
  • 15
  • 32

1 Answers1

3

You should use format strings instead:

pDate.ToString("0.0000")

or

pDate.ToString("n4")
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964