Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!