dshnx48866 2015-05-20 14:01
浏览 72
已采纳

PHP - 随机循环行为问题

I am actually facing a big problem with several websites (actually 3) based on Prestashop. The problem is that PHP or Prestashop randomly rounds prices to the nearest integer and it is not systematic.

Most of the time, it works perfectly, as it should, but sometimes (it can takes weeks or months between two problems), a price is rounded. My round mode option is correctly set to display two decimals.

The problem can occur when editing a product price in the back-office or when the customer is at the checkout step.

I tried to reproduce the problem, so I created a basic test: I retrieve a cart information and I display its price. I refreshed the page many times and I saw the price rounded a few times only. The most intriguous thing is that neither the context nor the code have changed between the beginning and the ending of the test.

I searched for help on Google and no one seemed to have this problem...

Did someone encounter this problem? Do you think it is a PHP issue or a Prestashop one? Thanks in advance for your help.

Here is the code of the round function Prestashop is using:

round($value, 2, PHP_ROUND_HALF_UP);

For information, the version of PHP 5.4.39.

  • 写回答

4条回答 默认 最新

  • douiwn6941 2017-10-05 14:57
    关注

    More than 2 years after, we figured out the issue. It was due to php5-fpm who does not handle locales per thread but per process. It is really clear in PHP documentation:

    Warning The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS, HHVM or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale().

    Because the decimal separator has changed, PHP did not recognize decimals and truncated my numbers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算