How to sort posts based on the value (number) of a post’s metadata?

To order using post based custom fields you have to store your variable in an actual field using add_post_meta or update_post_meta, or manually add it to the post field.

That way you can use WP Query to query the meta value for that field and order by the value. For example;

//adds a value to a field with the key name 'vote_field' and your variable.
<?php add_post_meta($post_id, 'vote_field', $votes_number); ?>

//query the key 'vote_field' and order by
$query = new WP_Query( array ( 
                             'post_type' => 'post', 
                             'meta_key' => 'vote_field', 
                             'orderby' => 'meta_value', 
                             'order' => 'ASC' ) );

Also there are additonal paramters you can use such as meta_value_num and ‘meta_compare