Get only X number of categories

After reading your question (and comment) again, this could be what you want to do:

$X = 3; // for instance
ob_start();
the_category();
$cats = implode('<li', array_slice(explode('<li', ob_get_clean()), 0, $X+1));

If you want to use this throughout your theme multiple times, use a function. Put the following in your functions.php:

function my_the_category($limit) {
    $limit++;
    ob_start();
    the_category();
    $cats = implode('<li', array_slice(explode('<li', ob_get_clean()), 0, $limit));
}

Now you can use <?php my_the_category(3); ?>, for example.