|
-
Dec 19th, 2009, 02:46 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] MySQL Query - Detect 2 numbers after =>
I have amount 200000000
How i can make echo show: 20000 Gold coins 00 Silver coins 00 Bronze coins?
Like: 20000,00,00 => put ',' mark two times to every two number?
-
Dec 20th, 2009, 01:22 AM
#2
Re: MySQL Query - Detect 2 numbers after =>
if the last four numbers are always the number of silver coins and bronze coins, and the remaining numbers denote how many gold coins there are, you can use the substr() function to break it up. I made this example:
PHP Code:
<?php //returns 20000,00,00 echo convertCoins(200000000) . "\n\n";
//returns 2,00,00 echo convertCoins(20000) . "\n\n";
//returns 2 echo convertCoins(2) . "\n\n"; function convertCoins($n){ $l = strlen($n); $coins = array(); //are there enough coins to show gold? if($l > 4){ //gold $coins[] = substr($n, 0, -4); //start at the beginning and go until the fourth-last character } //are there enough coins to show silver? if($l > 2){ //silver $coins[] = substr($n, -4, 2); //start at the fourth-last character and stop 2 characters later } //always calculate bronze //bronze $coins[] = substr($n, -2); //start at the second-last character and go until the end return implode($coins, ","); }
?>
there could be many additions made to suit this to more specific needs, but it should give you a general idea. ask questions if you need help.
-
Dec 20th, 2009, 06:38 AM
#3
Thread Starter
Hyperactive Member
Re: MySQL Query - Detect 2 numbers after =>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|