2011 Goal Update (January)

This is my first monthly report on how I’m doing with my goals for 2011:

  • Read the Book of Mormon again. This is going well. I’m using my Standard Works webpage to get emails that keep me on track with my studying.
  • Earn as much from my side business as I do from my day job. January has been an awful month for my revenue. Looking at my historic earnings, this is pretty normal for me for January. It isn’t all bad though. I’ve started making a tiny bit of money by selling access to the Fake Name Generator API. I’m going to expand the FNG API offering, and add a paid API for ABA Number Lookup.
  • Build a dining room table. Due to some problems finding appropriate wood and concerns with the difficulty in building nice chairs to go with the table (or finding matching chairs at a store), I’ve decided to change this goal to “Build a desk for our piano keyboard”. I’m currently sketching out plans for this piece of furniture, and hope to start on the actual construction of it soon.
  • Launch twelve new websites. I’ve launched MEID Converter, which is my first new site this year. I’ve also added a Smiley Generator to the Fake Name Generator. I’m not counting this as a new site, but it was fun to put together.

I’ve also been working on a few goals that I didn’t originally blog about:

  • Max out my 401k and Roth IRA contributions. I’ve been contributing the maximum allowed to my Roth IRA for a few years, but want to start saving more aggressively for retirement so I’m going to start maxing out my 401k, too. I’ve mailed in the paperwork to get the 401k started.
  • Get out of debt. My wife owes a tiny amount in student loans, and I’d like to get them paid off this year so we can be 100% out of debt. We’ve created a new spreadsheet that shows our assets and liabilities, and we are going to update it once a week to help us better see what we owe and what we have.
  • Start an email newsletter. There is big money in email newsletters. I haven’t settled on a topic yet, but I’d like to start an email newsletter and get 1,000 subscribers before the end of the year.
  • Create a game for mobile phones. I haven’t had a chance to play too much with mobile phone programming, but I’d like to take the time to create a basic game. Right now I’m settling on which language I’d like to use.
Read More

PHP’s [Lack of] Floating Point Precision

If you do a lot of programming in PHP, it is important to know that the way PHP handles floating points (like 1.0) has a few “gotchas” that you need to be on the look out for. In most cases, these issues won’t cause any major problems, but if you have a large invoicing or payment system that does hundreds or thousands of calculations, they could cause some serious issues.

For example, take this simple subtraction:

<?php

echo 20.01 - 20.00;
// Output: 0.010000000000002

Well that doesn’t seem right. Sure, rounding the number to two decimal places “solves” the issue. But what if instead of subtracting a floating point we were to compare two floating points?

<?php

$value1 = 10.00 + 2.88 + 2.88 + 2.88 + 9.00; // 27.64
$value2 = 27.64;

if ($value1 == $value2) {
    echo 'Equal';
} else {
    echo 'Not Equal';
}

// Output: Not Equal

Even though both values should be equal, PHP doesn’t think they are.

The problem is some values are difficult to store as binary, so PHP stores approximate values. This leaves us with the question is: how do you safely deal with floating point numbers in PHP?

The easiest way is to use BC Math. For the first example above, we’d do:

<?php

bcscale(2); // Set the default precision

echo bcsub(20.01, 20.00);
// Output: 0.01

The bcscale() function sets the default precision. If I didn’t specify the precision, bcsub() would have returned 0, because 20 – 20 = 0.

For the second example above:

<?php

bcscale(2); // Set the default precision

$value1 = 10.00 + 2.88 + 2.88 + 2.88 + 9.00; // 27.64
$value2 = 27.64;

if (bccomp($value1, $value2) === 0) {
    echo 'Equal';
} else {
    echo 'Not Equal';
}

// Output: Equal

Again, bcscale() sets the default precision so we can accurately compare the two numbers.

Read More

2011 Goals

It is a new year and time for new goals. There is a quote from Thomas S. Monson that I’ve always loved:

When performance is measured, performance improves. When performance is measured and reported, the rate of improvement accelerates.

I strongly believe in that statement, and so I’m going to start this year with several specific goals and keep track of my progress throughout the year. I plan on posting every now and then on my progress and hopefully I’ll be able to have several “I did it!” posts throughout the year.

For these goals I’ve chosen things that have a clear definition of what is needed for the goal to be considered accomplished. I’ve also left off goals that are easy to fail, such as “read the scriptures every day”. I’d love to read the scriptures every day but if I make that a goal and I miss a single day, then I’ve failed the entire goal.

Here they are, in no particular order:

  • Read the Book of Mormon again. It has been a while since I’ve read the Book of Mormon from start to finish. I have a handy website that helps create a reading plan, so I’m going to take advantage of it to keep me on track with this goal.
  • Earn as much from my side business as I do from my day job. In December, my side business made me about 70% of what I make at my day job. I think I have a real shot at getting that to 100% by the end of this year, which would make it possible to put a pile of money aside for retirement. This month is already off to a bad start (January is always a bad month for my side business), but I have a lot of coals in the fire and hope to get back on track real soon.
  • Build a dining room table. We’ve been looking for a dining room table for months and months, and have had very little success finding something we like. I’ve decided I want to make our table myself. I’m going to buy the wood, cut it, put it together, and finish it. I anticipate this costing a lot of money and time, but I think it will be worth it. If I get real ambitious, I’m going to make the chairs, too.
  • Launch twelve new websites. I want to create a new website every month. Once you have a server, the cost of starting a new website is just the cost of the domain (for me that is about $7.73/year, or $0.65/month). It doesn’t take much for a website to become profitable, and you never know which idea is going to take off and bring in a pile of money each month. I already have the domains registered for 7 ideas, and I’ve got a few more ideas that I’m still trying to find a good domain for, so all this will take is a bit of time and effort.

Well I think that is it. I have a lot of short term goals, like getting our TV mounted above the fireplace, but I don’t think those are worth listing.

Happy New Year! Good luck with all your 2011 goals!

Read More