The Ace Posted March 15, 2008 Posted March 15, 2008 How do I get rid of them? Whenever interest is gained, the money in the CyberBank and normal Bank go up by the whatever percentage, but then also have decimal places added on to them. In the code, I have got it as float, so there is no cap, but I can't seem to get the decimals to go. Have I got to change things in phpMyAdmin? Quote
topmorpg Posted March 15, 2008 Posted March 15, 2008 Re: Decimals in Banks round($gain); Round is good till the numbers get to high. Then they start not rounding dollars but rounding thousands and even hundred of thousands. Use something like floor($data) before inserting to your database. There are many methods for this. Just depends the use and outcome you want. Quote
The Ace Posted March 15, 2008 Author Posted March 15, 2008 Re: Decimals in Banks There are some quite big numbers...so, what do I use? Where does the floor($data) go? Quote
topmorpg Posted March 15, 2008 Posted March 15, 2008 Re: Decimals in Banks Example of floor() function <?php echo(floor(0.60) . " "); echo(floor(0.40) . " "); echo(floor(5) . " "); echo(floor(5.1) . " "); echo(floor(-5.1) . " "); echo(floor(-5.9)) ?> Output 0 0 5 5 -6 -6 Also what type of data storage type are you using? decimal, bigint, text, etc... Quote
The Ace Posted March 17, 2008 Author Posted March 17, 2008 Re: Decimals in Banks lol...still a bit confusing, but I'll see. Umm...I think I'm using FLOAT...but then it seems to change to DOUBLE. Is that OK? Quote
The Ace Posted April 3, 2008 Author Posted April 3, 2008 Re: Decimals in Banks I will be resetting my game, and I would like the decimals out of banks and money on hand....and I am not sure about the floor function...I am confuzzled! :? Quote
Floydian Posted April 13, 2008 Posted April 13, 2008 Re: Decimals in Banks Floor: 1.12413241324123 becomes: 1 1.9934939213493 becomes 1 12352341.12341324134 becomes 12352341 12352341.9913999919349134 becomes 12352341 $money = 12352341.99923993942; $money = floor($money); echo $money; // 12352341 personally, when I insert the data into the database, I do this: $q_update = sprintf('update users set bankmoney = "%.0f" where userid = %d', $money, $userid); %.0f, what that does is it formats your $money variable as a float with no decimals. %.3f would format it as a float with 3 decimal places: 1.2351451452 becomes 1.235 Then when you perform the query: mysql_query($q_update); and ya done You could apply the sprintf() function when you get data from the database: $money = sprintf('%.0f', $ir['money_field']); That is roughly equivalent to using the floor function, so floor is recommended for that. When inserting, updating the database, sprintf is preferred because you can cast the variable any way you want, at the same time that you cast other variables as well. Quote
The Ace Posted April 13, 2008 Author Posted April 13, 2008 Re: Decimals in Banks $money = floor($money); Whereabouts do I put/edit this? Quote
Floydian Posted April 13, 2008 Posted April 13, 2008 Re: Decimals in Banks put it in the cyberbank and any other bank make sure you have this code before you echo the variable I can't tell you exactly where in your code it should go as I don't have your code and I don't really remember how mccodes code goes. Just make sure you insert the floor function, with the proper variable in the argument, i.e., floor(proper variable here); and then echo the variable, or print it. lol Quote
The Ace Posted April 13, 2008 Author Posted April 13, 2008 Re: Decimals in Banks I'm stumped as well, because I can't find $money! Here is my bank code: <?php include "globals.php"; if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } print "<h3>Bank</h3>"; if($ir['bankmoney']>-1) { switch($_GET['action']) { case "deposit": deposit(); break; case "withdraw": withdraw(); break; default: index(); break; } } else { if(isset($_GET['buy'])) { if($ir['money']>49999) { print "Congratulations, you bought a bank account for £50,000! [url='bank.php']Start using my account[/url]"; $db->query("UPDATE users SET money=money-50000,bankmoney=0 WHERE userid=$userid"); } else { print "You do not have enough money to open an account. [url='explore.php']Back to town...[/url]"; } } else { print "Open a bank account today, just £50,000! [url='bank.php?buy']> Yes, sign me up![/url]"; } } function index() { global $db, $ir,$c,$userid,$h; print "\n[b]You currently have £{$ir['bankmoney']} in the bank.[/b] At the end of each day, your bank balance will go up by 2%. <table width='75%' cellspacing=1 class='table'> <tr> <td width='50%'>[b]Deposit Money[/b] It will cost you 15% of the money you deposit, rounded up. The maximum fee is £3,000.<form action='bank.php?action=deposit' method='post'> Amount: <input type='text' name='deposit' value='{$ir['money']}' /> <input type='submit' value='Deposit' /></form></td> <td> [b]Withdraw Money[/b] There is no fee on withdrawals.<form action='bank.php?action=withdraw' method='post'> Amount: <input type='text' name='withdraw' value='{$ir['bankmoney']}' /> <input type='submit' value='Withdraw' /></form></td> </tr> </table>"; } function deposit() { global $db,$ir,$c,$userid,$h; $_POST['deposit']=abs((float) $_POST['deposit']); if($_POST['deposit'] > $ir['money']) { print "You do not have enough money to deposit this amount."; } else { $fee=ceil($_POST['deposit']*15/100); if($fee > 3000) { $fee=3000; } $gain=$_POST['deposit']-$fee; $ir['bankmoney']+=$gain; $db->query("UPDATE users SET bankmoney=bankmoney+$gain, money=money-{$_POST['deposit']} where userid=$userid"); print "You hand over £{$_POST['deposit']} to be deposited, after the fee is taken (£$fee), £$gain is added to your account. [b]You now have £{$ir['bankmoney']} in the bank.[/b] [url='bank.php']> Back[/url]"; } } function withdraw() { global $db,$ir,$c,$userid,$h; $_POST['withdraw']=abs((float) $_POST['withdraw']); if($_POST['withdraw'] > $ir['bankmoney']) { print "You do not have enough banked money to withdraw this amount."; } else { $gain=$_POST['withdraw']; $ir['bankmoney']-=$gain; $db->query("UPDATE users SET bankmoney=bankmoney-$gain, money=money+$gain where userid=$userid"); print "You ask to withdraw $gain, the banking lady grudgingly hands it over. [b]You now have £{$ir['bankmoney']} in the bank.[/b] [url='bank.php']> Back[/url]"; } } $h->endpage(); ?> Whereabouts do you think I should put it? lol :) Quote
Floydian Posted April 13, 2008 Posted April 13, 2008 Re: Decimals in Banks <?php include "globals.php"; $ir['bankmoney'] = floor($ir['bankmoney']; $money is simply an example variable. lol Quote
The Ace Posted April 13, 2008 Author Posted April 13, 2008 Re: Decimals in Banks Thanks mate! Worked like a peach! (I knew that! not, lol). :) :-D Quote
Floydian Posted April 13, 2008 Posted April 13, 2008 Re: Decimals in Banks good deal, and you're welcome ;) Quote
The Ace Posted June 3, 2008 Author Posted June 3, 2008 Re: Decimals in Banks I made a donator bank from my cyberbank, and changed all the necessary things. The money in the bank changes, but it seems that the last three digits stay the same....seem to be rounded to "000". For example; I have £993512000 in my donator bank and £878 on hand. But, when I deposit my money, the bank money goes to: £993513000 (In the deposit screen it shows: £993512878) This is highly annoying!!!!! :x Quote
The Ace Posted June 8, 2008 Author Posted June 8, 2008 Re: Decimals in Banks May someone please help? :o) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.