New to Javascript and Vue. Trying to create a filter that formats single, double, or triple digit numbers. For a 1 digit number, I want it to be displayed as '#00X', for a 2 digit number as '#0XX', and for a 3 digit number as '#XXX'. This is what I have so far:
//Vue Filter
Vue.filter('number_filter', function (value){
if(value.toString().length === 1){
return '#00' + value;
} else if(value.toString().length === 2){
return '#0' + value;
} else {
return '#' + value;
}
});
The current issue is that the filter only returns '#X' when encountering a single digit number. How can I modify it to work correctly?