Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
Javascript - How to Transform MiB to GB

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

Result from function

I would like something like:

4.59 GB
4.19 GB
3.67 GB
2.61 GB
10 GB
20 GB
30 GB
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

MiB = 1,024 * 1,024 Bytes GB = 1,000 * 1,000 * 1,000 Bytes

Therefore you first have to multply your value by 1,024^2 and after that divide it by 1,000^3.

Your code should be something like this: (label * 1048576) / 1000000000 (yes, that is equivalent to your calculation).

Anyway, I guess the return value of your API is not in MiB, because the result of the calculation is 3 dimension to large.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda