I am trying to convert values from my API response, where I get the values in MiB. I need to convert these MiB values to GB to put the available server memory size in my graph, but I don't know where I'm going wrong.
Can you help me? I am a beginner in Angular.
My Code:
  this.chart = new Chart('canvas', {
          type: 'bar',
          data: {
            labels: this.serverName,
            datasets: [
              {
                data: this.serverMemory,
                borderColor: 'transparent',
                label: 'Full Memory',
                backgroundColor: '#007bff',
                borderWidth: 3,
                borderRadius: 10,
              },
              {
                data: this.serverMemoryUnused,
                borderColor: 'transparent',
                label: 'Memory Unused',
                backgroundColor: '#e3ebf6',
                borderWidth: 3,
                borderRadius: 10,
              },
            ],
          },
          options: {
            scales: {
              x: {
                display: true,
              },
              y: {
                beginAtZero: true,
                ticks: {
                  callback: (label: any) => `${label * (1048576 / 1000000000)} GB`
                   
                },
                grid: {
                  display: false
                }
              },
            }
          }
        });
My API is returning this: "4096000"
However, when passing this value to the function it returns all values as a float, I would like only 2 decimal places.
The function is returning this
4718.592000000001 GB
4194.304 GB
3670.016 GB
I would like something like:
4.59 GB
4.19 GB
3.67 GB
2.61 GB
10 GB
20 GB
30 GB
 
     
    