doushenyi9104 2018-09-27 13:37
浏览 103

如何在Woocommerce中制作千元分隔符

I wrote this code (on woocommerce/single-product/price.php) a few months ago but I lost it, I was lucky to recover the code but in its first phase. Before the result gave me a thousand separation, I think it was because of the "preg_replace" function.

<?php echo '$' . round((preg_replace('/^[\.]/', '', $product->get_price()) *1.04)); ?>

The result that shows me is similar to: $311896. The format I'm looking for: $311.896

I will show you how it works. I add a tax to a payment gateway (that's why I used formula x1.04). It is shown in this way: The original price if it is formatted correctly, but my code is not. It is a headache.

  • 写回答

2条回答 默认 最新

  • donglian4879 2018-09-27 13:46
    关注
    $a='299900';
    echo '$' . number_format($a*1.04); 
    

    the output is: $311,896

    if you want to display "." instead of the "," you can do that via the function extra parameters, see http://php.net/manual/en/function.number-format.php

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致