Digits of an Integer
Is it possible to format only a certain amount of digits from an integer when formatting into a string? Like you could with a float e.g "%.5f"?
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". |
Re: Digits of an Integer
PHP Code:
|
Re: Digits of an Integer
That worked pretty well. Thank you.
|
Re: Digits of an Integer
That will only work for values between 10,000 and 99,999,999.
What exactly are you trying to do? What situation would you only want the first 4 digits? |
Re: Digits of an Integer
Quote:
If he needs negative numbers below -10000, he can figure it out :D Quote:
What did you need it for anyways, i'm curious to know too :) |
Re: Digits of an Integer
Quote:
Quote:
|
Re: Digits of an Integer
Quote:
Quote:
PHP Code:
Code:
1234 |
Re: Digits of an Integer
Quote:
I needed to convert get_gametime() seconds to miliseconds and I found this post: Quote:
I'm still glad I learned the method you guys posted, I'm sure it'll come in handy one day. |
Re: Digits of an Integer
Quote:
If you need to convert between seconds and milliseconds, either multiply by 1000 to go from seconds to milliseconds or divide by 1000 to go from milliseconds to seconds (when dividing, make sure both numbers are floating point values). But, it sounds like you figured this part out. So, what happened in this thread is known as the XY Problem. To avoid this in the future, when asking questions, always explain what you are actually trying to do. |
Re: Digits of an Integer
I would actually prefer to get an answer to my questions as once you have a certain question you should always try to find an answer for it.
I'm sure taking only certain digits can be useful in certain situations. One that I can think of is showing a player's money in thousands. E.g $100216 -> $100k. Obviously you would need to adjust it to make sure it doesn't show 1234 as 123k and so on. I don't consider it a waste of time as it says in that XY problem page. I had a question and I got an answer and learned something, I'm thankful to those that answered. But lol @: Quote:
|
| All times are GMT -4. The time now is 17:52. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.