February 21st, 2013, 07:03 PM

Increase xval as string length decreases
I'm using a custom language and just need a little math help. PHP is close to the language so I figured I'd post here.

I'm outputting numbers to a string and everytime the string gets shorter, it moves all the numbers to the left(by 8 pixels).
I need it to keep the same xval.
My custom language allows "strlen" so I just need a formula that reads the string's length and keeps the number's in the same place.

new len = 8 * strlen(SpeedString);

Multiplying is incorrect because as the string gets larger is moves it a lot more to the right. Do I div, substract,..I forget.
If you don't understand any of my language, then create the math formula in php.
February 21st, 2013, 08:03 PM

This may be to obvious, but why not use textalign:right on the container that holds the digets?
February 21st, 2013, 08:06 PM

No such function for my custom language..I just need the math formula..feel free to make it look php just keep it simple.
February 21st, 2013, 08:19 PM

Originally Posted by KingOfHeart
No such function for my custom language..I just need the math formula..feel free to make it look php just keep it simple.
OK but how does the string gets shorter? are you subtracting? because this quotes implies you are adding number to a string.
Originally Posted by kingofhearts
I'm outputting numbers to a string and everytime the string gets shorter
Anyway what I would do is in case the string gets shorter because you are subtracting numbers (instead of adding( aka outputting))
knowing that each digits is 8 pixels long. Take the original string length multiplied by 8 if you take a number off 8 is added
could look like this I guess:
PHP Code:
new len = 8 * strlen(SpeedString) + 8;
Comments on this post
Last edited by aeternus; February 21st, 2013 at 08:21 PM.
February 21st, 2013, 08:27 PM

You helped a bit, this formula works.
24  (8 * strlen(SpeedString));
24 is the original length and I'm keeping it simple so I'm using the number 24 instead of using strlen for this part.