[Skip to main content](#vessel-content)

#   Make orders (and products) only save 2 decimals on the database

##

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

8 years 6 months ago [\#292371](#292371) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  *[Make orders (and products) only save 2 decimals on the database](/forum/35-orders-management/894652-make-orders-and-products-only-save-2-decimals-on-the-database#292371 "-- HikaShop version -- : 3.4.0 -- Joomla version -- : 3.8.1  Hi,  For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.  Is there some easy way to make it only save 2 digits?  For example:  If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like &quot;18.00&quot;.  Thanks in advance.  -- Victor")* was created by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")*

-- HikaShop version -- : 3.4.0
-- Joomla version -- : 3.8.1

Hi,

For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.

Is there some easy way to make it only save 2 digits?

For example:

If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like "18.00".

Thanks in advance.

--
Victor

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDY1Mi1tYWtlLW9yZGVycy1hbmQtcHJvZHVjdHMtb25seS1zYXZlLTItZGVjaW1hbHMtb24tdGhlLWRhdGFiYXNlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86583
- Thank you received: 14324
-
-

8 years 6 months ago [\#292387](#292387) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Make orders (and products) only save 2 decimals on the database](/forum/35-orders-management/894652-make-orders-and-products-only-save-2-decimals-on-the-database#292387 "-- HikaShop version -- : 3.4.0 -- Joomla version -- : 3.8.1  Hi,  For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.  Is there some easy way to make it only save 2 digits?  For example:  If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like &quot;18.00&quot;.  Thanks in advance.  -- Victor")*

Hi,

There are several ways:
- you could turn on the "round prices during calculations" setting. That way, the rounding would be done during the calculations and not only during the display and you would get a rounded total for the order.
- you could also modify the code in the createFromCart function of the file administrator/components/com_hikashop/classes/order.php to round the total when the order is being created: Code:

$order-&gt;order_full_price = $cart-&gt;full_total-&gt;prices[0]-&gt;price_value_with_tax;

- you could also create a plugin of the group hikashop, implementing the onBeforeOrderCreate trigger in order to do the rounding there.

The following user(s) said Thank You: [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDY1Mi1tYWtlLW9yZGVycy1hbmQtcHJvZHVjdHMtb25seS1zYXZlLTItZGVjaW1hbHMtb24tdGhlLWRhdGFiYXNlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

8 years 6 months ago [\#292442](#292442) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  Replied by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")* on topic *[Make orders (and products) only save 2 decimals on the database](/forum/35-orders-management/894652-make-orders-and-products-only-save-2-decimals-on-the-database#292442 "-- HikaShop version -- : 3.4.0 -- Joomla version -- : 3.8.1  Hi,  For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.  Is there some easy way to make it only save 2 digits?  For example:  If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like &quot;18.00&quot;.  Thanks in advance.  -- Victor")*

Hi,

Thanks for the answer.

It works fine, but the problem is that I really need to do it in all prices.

My customer only works in 2 decimals and using 5 of them it's a problem.

If I change the desired fields in the database to DECIMAL(17,2) it's going to work?

There will be some issue with that?

Thanks in advance.

--
Victor

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDY1Mi1tYWtlLW9yZGVycy1hbmQtcHJvZHVjdHMtb25seS1zYXZlLTItZGVjaW1hbHMtb24tdGhlLWRhdGFiYXNlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86583
- Thank you received: 14324
-
-

8 years 6 months ago [\#292449](#292449) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Make orders (and products) only save 2 decimals on the database](/forum/35-orders-management/894652-make-orders-and-products-only-save-2-decimals-on-the-database#292449 "-- HikaShop version -- : 3.4.0 -- Joomla version -- : 3.8.1  Hi,  For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.  Is there some easy way to make it only save 2 digits?  For example:  If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like &quot;18.00&quot;.  Thanks in advance.  -- Victor")*

Hi,

Ah yes, I didn't thought about that.
That's indeed a very good idea. If you change the type of the field in the database, then MySQL will round the values automatically for you:
[ dev.mysql.com/doc/refman/8.0/en/precision-math-rounding.html](https://dev.mysql.com/doc/refman/8.0/en/precision-math-rounding.html)
Note that as explained on that link, it's possible, based on your server, that the rounding is done differently than HikaShop, so for some payment plugins, it's possible that in some cases the rounding is done differently and could potentially be problematic.

The following user(s) said Thank You: [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDY1Mi1tYWtlLW9yZGVycy1hbmQtcHJvZHVjdHMtb25seS1zYXZlLTItZGVjaW1hbHMtb24tdGhlLWRhdGFiYXNlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")**
- [![PeterChain's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar570.png)](/forum/user/570-peterchain "View PeterChain's Profile") Topic Author
- [ Offline](/forum/user/570-peterchain)

Less More

- Posts: 640
- Thank you received: 16
-
-

8 years 6 months ago [\#292740](#292740) by [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")  Replied by *[PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")* on topic *[Make orders (and products) only save 2 decimals on the database](/forum/35-orders-management/894652-make-orders-and-products-only-save-2-decimals-on-the-database#292740 "-- HikaShop version -- : 3.4.0 -- Joomla version -- : 3.8.1  Hi,  For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.  Is there some easy way to make it only save 2 digits?  For example:  If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like &quot;18.00&quot;.  Thanks in advance.  -- Victor")*

Hi,

First of all, sorry for the delay.

Which rounding system uses Hikashop?

Thanks in advance.

--
Victor

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDY1Mi1tYWtlLW9yZGVycy1hbmQtcHJvZHVjdHMtb25seS1zYXZlLTItZGVjaW1hbHMtb24tdGhlLWRhdGFiYXNlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86583
- Thank you received: 14324
-
-

8 years 6 months ago [\#292751](#292751) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Make orders (and products) only save 2 decimals on the database](/forum/35-orders-management/894652-make-orders-and-products-only-save-2-decimals-on-the-database#292751 "-- HikaShop version -- : 3.4.0 -- Joomla version -- : 3.8.1  Hi,  For default, the numerical fields on orders, products, shippings and payments come this this database struct: decimal 17,5.  Is there some easy way to make it only save 2 digits?  For example:  If I create an order that have a total incoming of 17.99650 (without taxes), I want to save it in the database like &quot;18.00&quot;.  Thanks in advance.  -- Victor")*

Hi,

HikaShop rounds up from 5 to 9 and down from 0 to 4 (the default rounding of PHP) and what is usually done in real life.

The following user(s) said Thank You: [PeterChain](/forum/user/570-peterchain "View PeterChain's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzM1LW9yZGVycy1tYW5hZ2VtZW50Lzg5NDY1Mi1tYWtlLW9yZGVycy1hbmQtcHJvZHVjdHMtb25seS1zYXZlLTItZGVjaW1hbHMtb24tdGhlLWRhdGFiYXNlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.056 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
