DarrenReeder Posted December 6, 2009 Share Posted December 6, 2009 Hello, i am currently making a small game type thing and i want to have a money field... I have tried a few different field types to get exactly what i want but nothing seems to be working... i want to save money so its in the form 1,000,000 and then 560,000,000 e.t.c. so its easy to read for people... none of the int field types support the ',' as far as i know and ive tried a few thats its not working for... i decided that i should just use VarChar and enter 1,000,000 then echo that out to show ammount of cash i got and...it works!! However, i i have now started to use this field in code and im trying to check if i have enough cash by basicly doing code like this: if($mymoney < $neededmoney) { echo "test"; } However this is not working because i THInk its just thinks that the value of $mymoney is 1 (1,000,000)...Wen i type use 1 for the number then test will Show up however if i type 2 then it wont show.. (i think...im confusing myself) so anything i need a way of saving 1,000,000 as the number 1000000 - also ive tried useing INT for 1000000 but then it STILL just saves it as 1...when i echo this out it even shows it as '1' not '1000000'... any help would be great! Quote Link to comment https://forums.phpfreaks.com/topic/184131-setting-up-a-money-field/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 so its easy to read for people... When you display it, you format it with the 1,000 thousands separators. There is both a mysql FORMAT() function that you can use in a query and a php number_format() function that you can use in your presentation logic. Quote Link to comment https://forums.phpfreaks.com/topic/184131-setting-up-a-money-field/#findComment-972167 Share on other sites More sharing options...
DarrenReeder Posted December 6, 2009 Author Share Posted December 6, 2009 What field type do i use on the field? so if i have 1000000 it will echo it as 1000000 and not 1 Quote Link to comment https://forums.phpfreaks.com/topic/184131-setting-up-a-money-field/#findComment-972174 Share on other sites More sharing options...
PFMaBiSmAd Posted December 6, 2009 Share Posted December 6, 2009 The only reason you are getting a 1 when you entered the value 1,000,000 is that the comma is a STOP character and the number was not parsed beyond that point when it was entered. Use a DECIMAL data type. Quote Link to comment https://forums.phpfreaks.com/topic/184131-setting-up-a-money-field/#findComment-972177 Share on other sites More sharing options...
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.