Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define Money Fomat in Laravel

Tags:

laravel-5.1

I am trying to save money format in laravel 5.1.

Here is table price define:

$table->decimal(price,6,2);

For instance ; when 1.000,50 Turkish Liras saving to MySQL this format 1.00

How can solve this issue?

like image 814
badman Avatar asked Nov 04 '15 07:11

badman


People also ask

What is the money format?

United States (U.S.) currency is formatted with a decimal point (.) as a separator between the dollars and cents. Some countries use a comma (,) instead of a decimal to indicate that separation.

How do you convert numbers to money format?

On the Home tab, click the Dialog Box Launcher next to Number. Tip: You can also press Ctrl+1 to open the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Currency or Accounting. In the Symbol box, click the currency symbol that you want.


1 Answers

You can try defining your price like this

$table->decimal('price',9,3);

Where,

9 is the precision, ie 1234567.89 has a precision of 9

3 is the number of decimal places, ie 123456.789 has a scale of 3

In other words, if we use less decimal-places than 3, we can use remaining for real-number places.

You can refer to this link for about precision and scale of database How do I interpret precision and scale of a number in a database?

like image 174
Saad Avatar answered Sep 20 '22 16:09

Saad