rust string str?你想在Rust学习吗?Go考虑简单字符串插值特性
大家好,我是煎鱼。在日常开发 Go 工程中,我们经常会用 fmt.Printf 或 fmt.Sprintf 去写类似的拼装字符串的业务。如下代码:fmt.Printf("Hello Gopher %s
2021-12-11 09:13:12
134
查了一下博客的单篇文章的浏览数,发现有的文章的浏览数已突破了万级别,为了便于浏览数的可读性就想着用php将浏览数转换成带的单位的字符串,比如2千,1.2万等。
php 将数字转成带有千/万单位的字符串php自定义函数代码:
/** * @param int $num 要转换的阿拉伯数字 * * @return string 转换成的字符串 * http://feiniaomy.com */ function convert($num) { if ($num >= 100000) { $num = round($num / 10000) .'万+'; } else if ($num >= 10000) { $num = round($num / 10000, 1) .'万+'; } else if($num >= 1000) { $num = round($num / 1000, 1) . '千+'; } return $num; }
函数调用:
echo convert(12560); //1.3万+ echo convert(1256); //1.3千+
PS:有的博客站喜欢使用字母“k”来代替 "千",以“w”来代替“万”。所以上面的自定义函数代码可以修改如下:
/** * @param int $num 要转换的阿拉伯数字 * * @return string 转换成的字符串 * http://feiniaomy.com */ function convert($num) { if ($num >= 100000) { $num = round($num / 10000) .'w+'; } else if ($num >= 10000) { $num = round($num / 10000, 1) .'w+'; } else if($num >= 1000) { $num = round($num / 1000, 1) . 'k+'; } return $num; }
26
2023-02
30
2022-11
30
2022-11
29
2022-11
29
2022-11
29
2022-11