显示1k而不是1,000 [英] Show 1k instead of 1,000

查看:183
本文介绍了显示1k而不是1,000的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数restyle_text($ input){
$ input = number_format($ input);
$ input_count = substr_count($ input,',');
if($ input_count!='0'){
if($ input_count =='1'){
return substr($ input,+4)。'k';
} else if($ input_count =='2'){
return substr($ input,+8)。'mil';
} else if($ input_count =='3'){
return substr($ input,+12)。'bil';
} else {
return;
}
} else {
return $ input;




$ b这是我的代码,我认为它是加工。显然不是......有人可以帮忙,因为我无法弄清楚这一点。 试试这个:



http://codepad.viper-7.com/jfa3uK

  function restyle_text($ input){
$ input = number_format($ input);
$ input_count = substr_count($ input,',');
if($ input_count!='0'){
if($ input_count =='1'){
return substr($ input,0,-4)。'k';
} else if($ input_count =='2'){
return substr($ input,0,-8)。'mil';
} else if($ input_count =='3'){
return substr($ input,0,-12)。'bil';
} else {
return;
}
} else {
return $ input;


基本上,我认为你使用 substr()错误。


    function restyle_text($input){
    $input = number_format($input);
    $input_count = substr_count($input, ',');
    if($input_count != '0'){
        if($input_count == '1'){
            return substr($input, +4).'k';
        } else if($input_count == '2'){
            return substr($input, +8).'mil';
        } else if($input_count == '3'){
            return substr($input, +12).'bil';
        } else {
            return;
        }
    } else {
        return $input;
    }
}

This is the code I have, I thought it was working. apparently not.. can someone help since I can't figure this out.

解决方案

Try this:

http://codepad.viper-7.com/jfa3uK

function restyle_text($input){
    $input = number_format($input);
    $input_count = substr_count($input, ',');
    if($input_count != '0'){
        if($input_count == '1'){
            return substr($input, 0, -4).'k';
        } else if($input_count == '2'){
            return substr($input, 0, -8).'mil';
        } else if($input_count == '3'){
            return substr($input, 0,  -12).'bil';
        } else {
            return;
        }
    } else {
        return $input;
    }
}

Basically, I think you're using the substr() wrong.

这篇关于显示1k而不是1,000的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆