JSFiddle - React, Tailwind, and code Playground

JavaScript

console.clear();

setTimeout( function() {

  var mybag = []; 

  mybag[0] = "20.502"; 
  mybag[1] = 10.13;
  mybag[3] = 0;

  var active_mybag = [];  
  
  var total_w = mybag.reduce(function(acc,e){
    e = parseFloat(e);
    active_mybag.push( e.toFixed(2) );
    return acc + e;
  },0).toFixed(2);
  
  active_mybag = active_mybag.join(',');
  
  console.log('> ', 
              total_w, 
              active_mybag
  );
  
}, 500);