-1

私はのような5桁の数字を持っていますが、最終的には6桁になるので、として10000表示したいと思い10kます(実際、Twitterのカウントについて話しています)。部分文字列が必要だと思いますが、JavaScriptにはまだ慣れていません。

これが私が使おうとしているものです。基本的にはフォロワー数をJSONで取得します。

<script type="text/javascript">
    $(function() {
        $.ajax({
            url: 'http://api.twitter.com/1/users/show.json',
            data: {
                screen_name: 'lolsomuchcom'
            },
            dataType: 'jsonp',
            success: function(data) {
            $('#followers').html(data.followers_count);
                }
        });
    });
</script>
4

2 に答える 2

3

試す :

$('#followers').html(Math.floor(data.followers_count/1000) + 'K');
于 2013-01-15T01:08:59.803 に答える
2
$('#followers').html(data.followers_count.substring(0, data.followers_count.length - 3)); 

デモ: http://jsfiddle.net/ZWfPW/

編集..これがあなたのためだけのリテラルコードです:

$(function() {
    $.ajax({
        url: 'http://api.twitter.com/1/users/show.json',
        data: {
            screen_name: 'lolsomuchcom'
        },
        dataType: 'jsonp',
        success: function(data) {
            // Ensure it's a string
            data.followers_count += '';
            $('#followers').html(data.followers_count.substring(0, data.followers_count.length - 3) + 'K');
        }
    });
});
于 2013-01-15T00:53:55.693 に答える