Quote:
Originally Posted by PartialCloning
Lets say the integer is 12345678. Formatting that into 4 digits should turn it into 1234. While if my number was 23, it would be formatted as 0023. I know you can do the latter by doing "%04i".
|
Quote:
Originally Posted by fysiks
No, he said if his number was 4 digits or less. He said "formatting into 4 digits" which is illogical for numbers with more than 4 digits. At that point it's not a format, it's actually changing the value to something else. It would be logical to say "format into at least four digits" which is what %04i does.
Neither of those suggestions make make sense for getting the 4 left-most digits.
|
What safetymoose provided does what the OP asked for, fysiks, regardless of if it makes logical sense to do so. I am also curious why you would want the left-most 4 digits.
PHP Code:
new iVal = 12345678
while(iVal>10000)
iVal /= 10
server_print( "%04d" , iVal );
iVal = 23
while(iVal>10000)
iVal /= 10
server_print( "%04d" , iVal );
Output
__________________