DedeCMS织梦

织梦DedeCMS转换数字函数代码

阿里云

这个需求是在织梦官方群里看到一个群友提出的,要实现网站中的数字自动转换为 X 千、X 万 X 千这样的表现形式。这个想法很独特,不过也很实用,特别对于那些频繁展现数字的网站来说。其实实现起来很简单,只需要在 include\extend.func.php 加个函数 即可。

具体代码:

  1.     function click_round_number( $number, $min_value = 1000, $decimal =){
  2.      if( $number < $min_value ) {
  3.     return $number;
  4.     }
  5.     $alphabets = array( 100000000 => '亿', 10000 => '万', 1000 => '千' );
  6.     foreach( $alphabets as $key => $value )
  7.     if( $number >= $key ) {
  8.      return round( $number / $key, $decimal ) . '' . $value;
  9.     }
  10.     }
也想出现在这里?联系我们
创客主机

调用方式:

  1. {dede:field.click function=click_round_number(@me)/} //以调用点击数字为例

实现效果为:1 万 3 千 4 百 2 十 5

织梦 DedeCMS 转换数字函数代码

已有 292 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!