Update: C# Money/Currency Class

I received an email from Alexadre Boyer regarding a feature of my implementaiton of the Money class.
My C# implementation of the Money class was, originally, a port of the Money Pattern outlined in Martin Fowler’s book, Patterns of Enterprise Application Architecture. In the sample provided by Fowler, the amount is stored as a double. To avoid the floating point rounding problem, the authors implemented a scaled integer. In my original implementation, I used a long to represent the value and implemented the same pattern to avoid the floating point rounding problems. I’ve since refactored it to use decimal (making rounding decisions a responsibility of an external entity) and, in hindsight, it appears as though I should likely remove the CentFactor (or make it a public read-only property for those who may have a use for that value) as it, a) only serves to decrease performance in determining Amount, and b) the intent of the current implementation (now) is to force rounding to be taken care of external to the class.

I’ve made the change and republished the code.
Thank you, Alexandre, for noticing that oversight!


One thought on “Update: C# Money/Currency Class

  1. I’m going to implement the all patterns of PEAA in C# 2.0. Are you interested in it? Maybe we can work together to finish this task:) Or, maybe some suggestions is also OK.
    Contact me with my email.  Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s