Extra Fox – A blog by Christopher Taylor

Rounding Doubles to Integers in C#

Posted in Uncategorized by extrafox on August 31, 2006

I looked all over the place in the C# libraries for a simple method to round a Double to an Integer. I finally gave up and decided that such a thing may not actually exist. So, I went out on the net to find someone else’s implementation, but I didn’t like the one that I did find. So, here is my take on the problem…

public static long Round(double d) {
double ceilD = (double)Math.Ceiling(d);
double floorD = (double)Math.Floor(d);

// is the original double closer to the ceiling?
return ((ceilD - d) < (d - floorD)) ?
(long)ceilD : (long)floorD;
}

I’m not sure about efficiency, but there is a certain elegance to this approach. Hope it is useful for someone.

UPDATE: don’t know how I missed this one… [abstracttb.com]

Advertisements

Mycelio is getting off the ground

Posted in Uncategorized by extrafox on August 14, 2006

View east from MycelioBack in January, I ventured down to Oaxaca, Mexico with my good friend, Matt Brown. I was going for time off and a little adventure, but his goals were far more ambitious. Matt was embarking to start an organization to promote sustainability in a region that will soon be affected by growth.

Since January, he has managed to establish himself in Playa Zipolite, has bought and is developing property, and is now working with some local projects. I invite you to check out his website [Mycelio.org] where he explains everything in detail.

Vote for the cutest kittens at Kittenwar

Posted in Uncategorized by extrafox on August 10, 2006

I saw this site [Kittenwar.com] while looking at a completely unrelated site [Wired.com]. Very cute… The site gives you comparison after comparison of cat photos. Simply click on the one you like most and keep going until you get board. The site ranks the most clicked on photos. The goal? To waste as much time as possible (blog editing included).