driven22 Posted February 19, 2022 Posted February 19, 2022 In admin, entering the product weight 0.51 after saving, I still have 0.00. When I type 1.2 after saving I have 1. Oscommerce 2.3.4.1 CE, php 7.4. I am asking for help, I have a problem with incorrect decimal rounding in several places. // Wrapper function for round() function tep_round($number, $precision) { if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.') + 1)) > $precision)) { $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1); if (substr($number, -1) >= 5) { if ($precision > 1) { $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision - 1) . '1'); } elseif ($precision == 1) { $number = substr($number, 0, -1) + 0.1; } else { $number = substr($number, 0, -1) + 1; } } else { $number = substr($number, 0, -1); } } return $number; }
driven22 Posted February 20, 2022 Author Posted February 20, 2022 In db also the differences between what is visible in the store and what is in db. Same in oreders_products. Final price rounded down .How to fix it?
Jack_mcs Posted February 20, 2022 Posted February 20, 2022 The function you showed is the standard one and works fine in other shops so that is not the problem. My guess is that your code has been altered somehow to cause this or maybe your database was changed for some reason. You will need to troubleshoot it to find out what is going on. I suggest that after this line in the admin function On 2/19/2022 at 3:32 AM, driven22 said: function tep_round($number, $precision) { add the following: echo 'Price '. $number . ' Precision: ' . $precision; return '1.23'; Then change a price for a product. The above change will display what is sent to that function and then replaces it with a value. Make sure the price you entered is showing with that new code and that the saved value is the new one. If the full price is not being sent to the function then something in the categories file has been changed to alter the price. If the price sent is correct but the new figure is not stored then the problem is in the saving to database code or the database. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
driven22 Posted February 21, 2022 Author Posted February 21, 2022 I changed to admin / general to function tep_round($number, $precision) { echo 'Price '. $number . ' Precision: ' . $precision; return '1.23'; } but nothing has changed. I think the "," and "." are misinterpreted" .In data transfer shop -> db. In admin / Currency I changed decimal point to "." and thousands point was "," but it also didn't help. I changed the languages / english setlocate to LC_TIME to LC ALL in the file but it also did not help. I don't know where to look for the reason why this is happening. When I type the weight of 0.51 kg in the product after writing the rounds down to 0.00. The price of the product is remembered on the store's side, but already rounded down in the database. In admin / special, when I want to enter a discount from 25 to 24.50 round down to 24. When I want to make a percentage discount, it also calculates incorrectly. This came after switching from PHP 7.2 to 7.3 / 7.4. It looks like a simple mistake - but I don't know where to look.
driven22 Posted February 21, 2022 Author Posted February 21, 2022 One more thing. in the admin, when changing the price of the product, if I enter 25.60 and save - when I go back to the edition of the product, I have a value of 25.60. If i enter 25,60 after writing and editing the product, the price is rounded to 25.00 (as it is seen in the database). It would be a problem with the decimal interpretation ( "," and ".").
driven22 Posted February 21, 2022 Author Posted February 21, 2022 This has changed in the overview of the products after function tep_round($number, $precision) { echo 'Price '. $number . ' Precision: ' . $precision; return '1.23'; }
Jack_mcs Posted February 21, 2022 Posted February 21, 2022 @driven22 Both values are wrong. The price is what the code is being told to round. Assuming you entered a number with a fractional part, that is being removed before it gets to the round function. And the precision should be a number, like 2, as I recall. Take a look in admin->Localization->Currencies and make sure the default currency is setup correctly. You may want to delete it and add it back in to make sure the database entries are not corrupted. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
driven22 Posted February 21, 2022 Author Posted February 21, 2022 I removed the currency and added it again. Unfortunately, nothing has changed. Order Total in the admin is ok, the database is rounded to full values
driven22 Posted February 21, 2022 Author Posted February 21, 2022 On the other hand, it works without any problems - I enter order total in the database, for example, 25.56 and that's what I have in admin. The same with the weight - everything is OK. Unfortunately, when I enter order total, special, weight from the store's side towards the database, I have values rounded down to whole numbers.
driven22 Posted February 21, 2022 Author Posted February 21, 2022 Someone had the same problem before https://www.oscommerce.com/forums/topic/191077-problem-with-price-cutting-off-rounding-last-2-digits/ . I changed the final price as in the post but still just as stuck as the author of the post.
Hotclutch Posted February 23, 2022 Posted February 23, 2022 11 hours ago, driven22 said: Ok, I solved this problem You should post the solution for the benefit of others, or next time they may not be inclined to help you.
driven22 Posted February 23, 2022 Author Posted February 23, 2022 For half a year I was looking for a solution, so let me give the solution after 24 hours of tests.. Problem was as I had suspected in the interpretation "," and "." shop - db. Despite writing in lanugaes / english @setlocale (LC_TIME .... or LC_ALL did not work. But after typing in aplication_top.php (also in admin):setlocale(LC_ALL, "pl_PL"); setlocale(LC_NUMERIC, 'C'); Weight works fine in categories, also price, order_total, special (by price and%), export csv displays original values. I have been looking for a solution for over half a year on the forum, trying in the store. There was info everywhere that setlocale only fits in languages. Something was probably blocking setloc but hence the problem (but I can see, not only for me). A simple solution, and I spent so much time on it .. ahh
Recommended Posts
Archived
This topic is now archived and is closed to further replies.