• 0

[C#/ASP.NET] truncating a decimal


Question

Hi guys, my system keeps outputting decimals at x.xxxxxxx when I just want them to be x.xx. Is there a truncate method out there for this? I saw Decimal.Truncate but I don't get how to specify a dymanic variable being truncated. Just says input decimal to truncate...how to I tell it how many to format it to?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

decimal result = decimal.Round(decimalValue, 2);

That should do it. If you're using a value instead of variable make sure you put an m after it or the compiler will think it's a double value.

example:

decimal result = decimal.Round(3.1415m, 2);

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.