1

We have a plugin that takes orders from CarthThrob and then creates a special file for the distributor. This plugin grabs the order information and converts it to a special file type and format they use to fulfill orders. One part of that is to take the three letter country code and convert that to the three digit currency code. It works for most countries, however those that start with a zero don't work.

What we find is that instead of converting the letter code to the right numeric code it converts AUS (should be 036) to 030, Armenia (051) to 041, and Argentina (032) to 026?

This mightn't be a question for the EE community, but thought I'd start here in case someone can see a pattern or maybe it is some binary thing that is doing math and converting that to a different number.

Sample of the code (not all of it):

private function alpha_three_to_numeric_country($country)
{
    switch ($country) {
    case "AFG":
        return 004;
        break;
    case "ALA":
        return 248;
        break;
    case "ALB":
        return 008;
        break;
    case "DZA":
        return 012;
        break;
    case "ASM":
        return 016;
        break;
    case "AND":
        return 020;
        break;
    case "AGO":
        return 024;
        break;
    case "AIA":
        return 660;
        break;
    case "ATA":
        return 010;
        break;
    case "ATG":
        return 028;
        break;
    case "ARG":
        return 032; etc...
4

I'm no expert, but I don't think numbers that start with a zero are programatically treated as integers (some Googling suggests they are treated as something called Octals).

In your case, unless you need to do mathematical operations on those values, why not just declare them as strings by putting quote marks around them?

private function alpha_three_to_numeric_country($country)
{
    switch ($country) {
    case "AFG":
        return "004";
        break;

https://stackoverflow.com/questions/2495611/working-with-php-octals-and-string-conversions

1
  • Bingo. wow...so simple and yet at first seemed so random. We thought it was exclusive to Australia, but only because we had not had any orders from other countries that had a code starting with 0. Once I noticed that pattern I figured it had to be something like this. Thanks so much! – Doug Jan 17 '14 at 1:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.