Raised This Month: $ Target: $400
 0% 

Digits of an Integer


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-04-2015 , 21:14   Re: Digits of an Integer
Reply With Quote #7

Quote:
Originally Posted by PartialCloning View Post
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 View Post
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
Code:
1234
0023
__________________

Last edited by Bugsy; 12-04-2015 at 21:15.
Bugsy is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode