Monday, September 15, 2008

Scientific Notation to Decimal

I recently had a situation come up where I needed to convert numeric data that was in scientific notation to a decimal. As an example I would receive a string that was in the form 1E-9. The decimal representation of this is 0.000000001. Seems simple enough.

string sVal = "1E-9";
decimal val = Convert.ToDecimal(sVal);

The above code fails because ToDecimal uses NumberStyles.Number which doesn't include the AllowExponent switch. You'll receive a FormatException exception that states the input string was not in a correct format. Use the following to convert to a decimal.

string sVal = "1E-9";
decimal val = 0M;

if(!Decimal.TryParse(sVal, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out val))
val = 0M;


Friday, September 12, 2008

Mirra, Mirra, who's the fairest of them all.

I've always wanted a nice home office. Back in December we bought a new house and I finally had the opportunity to set up a nice home office. Now that my office is on its way to being a sanctuary of productivity, I needed a nice office chair to finish the package. I shopped all over for office chairs. The the major retailers, and online. None really fit what I wanted. I had bought cheep chairs before, and they only really last a couple of years and don't support your body the way it should be. Then I started a new job, and the chair they provided was a nice ergonomic chair. Its a Hon. I finally thought I found the chair. I searched down a local retailer and went into their show room to check them out. Turns out this retailer does sell Hon chairs, but they are primarily a Herman-Miller dealer. I never really sat in a Herman-Miller so I tried out the Herman-Miller Mirra. The fit was right. The support was there. But that much money, and I wasn't sure how it is sitting in front of my desk with it. The selling point, they let me take home a trial Mirra chair for two weeks before I bought. Wow...lets do it. When I got the Mirra home, I immediately put it in front of my desk and I was sold. Hands down it is the best chair out there. After my two weeks was up I returned the trial chair and ordered one of my very own. Its a small investment, mine was $710.00. But if you spend a lot of time at your desk, its worth the investment. The construction is solid, the support is second to none. And it has a 12 year warranty. That right there pays for itself. If you're serious about getting a nice chair check out the Mirra.