Jump to content

numbers to letters


M.O.S. Studios

Recommended Posts

I want to  be able to convert numbers to their letter equivalent. However I need it to go past 26 values.

 

here is the code

    function letters($value){
        if(!is_integer($value) && $value > 0){return false;}
        if($value < 26){return base_convert($value+10, 10, 36);}else{
            $tester = $value / 25;
            $tester = explode('.', $tester);
            return base_convert($tester[0]+9, 10, 36).letters($value*($tester[0]) - 26);
        }
    }

    echo $welcome."\n".$questions;
        for($i=0; $i<= 200; $i++){
        echo letters($i).$i."<br>";
    }

 

the problem happens after value 49.

 

 

any ideas?

Link to comment
Share on other sites

The quick view list two problems

 

1.$tester = $value / 25; to $tester = $value / 26; 

 

This will resolve your problem after value 40

 

secondly, you are calling recursively function letters() and in your function letters() there is not exit condition hence when the value reaches to 52.... it  recursively call letter() function and results in different character string. You need to control the execution of letter() function on some condition.

 

Thanks.,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.