c# variable types for financial data

I currently have a ton of numbers in my classes that are either doubles of floats.  I am going to standardize and make them consistent.  I really just need two decimal places and I hate the extra decimal places these variables have.  What kind of variable should I use?  I really just need the 2 decimals.

Who is Participating?
RouchieConnect With a Mentor Commented:
I believe the System.Decimal type is the one you need, however, if you are only using two decimal places then double will suffice.  Be aware however, that when rounding to two decimal places, you risk 'losing' a lot of money!

Its often best to display long decimals to two decimal places like this, which retains the original value:


Open in new window

käµfm³d 👽Connect With a Mentor Commented:
I agree (partially) with the above:  decimal has greater precision than double does, and it should be used whenever you are performing financial calculations.
Asim NazirConnect With a Mentor Commented:

For financials, Decimal is used as the most suitable data type and we normally store data with more than 2 decimal places but off-course we can show it to user with just two decimal places.

So, for display purpose, you can just format data to two decimal places following:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.