PHP: Simple recursive function into iterative function?

If you're looking for a conversion to string for big unsigned integers, the code is actually: function intToString($myDecimal) { return sprintf('%u', $myDecimal); } If you need to do it with iteration: function intToString($myDecimal) { $result = ''; while ($myDecimal > 9) { $result = ($myDecimal % 10) . $result; $myDecimal /= 10; } return $myDecimal . $result; } UPDATE: My bad, digits were inserted in reversed order.

Now it should work. Sorry, untested too.

I was wanting to do it in C, which used no standard functions (so sprintf is out), your second example spits out "02" instead of "20", weird. I am really just helping somebody do this in C, I will stop wracking my mind and go to sleep. :) – John Nov 5 '10 at 9:59 I updated my answer, you were right, it built the string in reverse order.

Now it should work fine. I hope. – xPheRe Nov 5 '10 at 10:02 Ah!

After some sleep I understand this now, it works perfectly and applies to the problem I wanted to help somebody with. It should be simple to do in C now (with simple ASCII addition). Thank you – John Nov 5 '10 at 19:04.

PHP is not very strict with variables. An integer will become an float if the situation likes it. In your code, $myDecimal /= 10 could make a float of $myDecimal.

The following forces $myDecimal to stay an integer. Note: you should pass only integers, if you're passing 9.99, the output would still be 9.99 because 9.99 = 10) { $myDecimal = (int) ($myDecimal / 10); $out . = $myDecimal; } $out .

= $myDecimal % 10; return $out; }.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions