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

363
Vistas
Format number with the thousand separator in Vue

I have division calculator and its working clearly but Im not happy with calculation result.You will understand better when you see the SS below.What I want is to delete unnecessary zeros, put commas where necessary, and show a more understandable number if the result shows the number thousand. For e.g: Not 19350.00 , this should be 19,350

Result

enter image description here

What I want

enter image description here

Template

  <input
    type="text"
    class="form-control h-35"
    autocomplete="off"
    v-model="purchasePrice"
  />
  <input
    type="text"
    class="form-control h-35"
    autocomplete="off"
    v-model="salePrice"
  />

  <p>{{ marginResult }}</p>

Script

data() {
    return {
      purchasePrice: null,
      salePrice: null,
      marginPrice: null,
    };
  },
  computed: {
    marginResult() {
      const res = parseFloat(
        ((this.salePrice - this.purchasePrice) / this.salePrice) * 100
      ).toFixed(2);
      if (isNaN(res) || res == "-Infinity") {
        return "";
      }
      return res;
    },
  },
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just use the Intl.NumberFormat utility object to format the number :

...
return new Intl.NumberFormat('en-US').format(res);
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