Don't add the euro sign in the database, use PHP money format for that.
As for the table field, use decimal(10,2) or something
Related double post? https://laracasts.com/discuss/channels/general-discussion/money-objects-and-form
Summer Sale! All accounts are 50% off this week.
Hello,
Can I have a input field which looks like this
€ and then the input field with on Thousand a . and and a . for the cents.
Roelof
Don't add the euro sign in the database, use PHP money format for that.
As for the table field, use decimal(10,2) or something
Related double post? https://laracasts.com/discuss/channels/general-discussion/money-objects-and-form
Thanks, I say somewhere a page on the net a page where a array was used to make a number field working with decimals. But I cannot find it.
If you're trying to style the UI, then something like this might help if you're using Bootstrap: http://getbootstrap.com/components/#input-groups-basic
As for formatting the numbers with the separaters and dots, as @bashy said, check out number_format and money_format.
Hi @roelof, you can find some tips about working with money and currency:
http://culttt.com/2014/06/04/working-money-currency-php/
Hope it helps you to decide how implement in your application.
Some other posts about it: http://culttt.com/search/?q=money
Thanks,
I have read that and I want to implement that way.
But I do not have a idea how I can take care that a user enters a decimal and I convert it to a integer before storing into the database.
I know I can multiply it by 100 but how to do that on the store method.
Hi @roelof, try using the following jQuery plugin:
https://github.com/RobinHerbots/jquery.inputmask
With this plugin you can force the user to enter the value of currency as you want , later the in example, you can get the Input::get('currency') from the request to a Command or simply request the value in the Controller method and make the calculation to maintain or store it on the DB.
Enter it into the database as a decimal(10,2) or however many decimal places you want your amount to be.
Create a helper that does something like this
// May need to set this somewhere unless you have it set
setlocale(LC_MONETARY, 'en_GB.UTF-8');
// This is where you convert decimal to amount like £1,337.00
return money_format('%n', $currency);
+150 Currencies https://github.com/Pharaonic/laravel-money
Please or to participate in this conversation.