Things I’ve learnt lead to badness…

    Some of these I’ve done.. some I’ve just seen.. but they are all now things I watch for…

  1. Never talking to someone who is going to physically use your solution…
  2. Not having acceptance tests…
  3. Showing up for your new job and being handed a few binders worth of the design that someone who has already quit did…
  4. Working at the same job for so long that it makes you think about becoming an electrician…
  5. Not practicing TDD…
  6. Having only half a team that understands DDD but trying to do it anyway…
  7. Not listening to your gut for a hiring decision…
  8. Writing integration tests to do the job of acceptance tests...
  9. 3 BAs for 10 developers..
  10. 2 QA people for 10 developers…
  11. Not understanding your audience…
  12. Listening too much to others…
  13. Too much reading.. not enough doing…
  14. Thinking that you know everything…
  15. Believing that you know nothing…

I could keep going but this seems like a good enough place to stop for my upcoming rant…

Rounding up to the nearest 0.05

Recently I ran into an interesting problem on a small project I was working on.  The problem was on the surface fairly simple.  Take a currency amount and round it up to the nearest 0.05.  While the solution is not earth shattering it took long enough to figure out that I figured it was worth recording for my future self. 

The first part of the problem is to round to 0.05 which is accomplished by doing this (thanks Google..):

decimal initialValue = 0.56;

decimal value = Math.Round(initialValue / 5, 2) * 5; 

But the problem is this code will actually round to the nearest 0.05 as opposed to only rounding up.  So 0.62 will round to 0.60 where as our requirement is to round to 0.65.

But that part of the problem is actually fairly easy to solve..

 

if((value - initialValue) < 0)
{
     value += 0.05m;
}
 

And there you have it.  We can now round up to the nearest 0.05.