0

I have a problem in removing a comma in a value using Vue.js. Following is my code:

displayValue(){
    var displayValue = this.value;
    console.log(displayValue);
    if(displayvalue has comma){
        displayvalue = displayvalue(remove comma)
    }
}

I've tried using indexOF() but it's not working.

Before .replace: enter image description here

After.replace: enter image description here

1
  • Is the comma for a numeric value's thousands separator? Be careful - in some regions comma is used as a decimal separator and dot is used for thousands. Commented Mar 28, 2018 at 6:18

2 Answers 2

2
if (displayvalue.indexOf(',') !== -1) {
  displayvalue = displayvalue.replace(/,/g, '');
}
Sign up to request clarification or add additional context in comments.

2 Comments

I'm sorry but is not working. Throws an error .includes is not a function .... Thanks.
You must be using an old browser (which is not recommended for web development). Edited answer
0

Just replace , using replace

displayValue(){
    var displayValue = this.value || ""; //check if this.value is null
    displayValue = String(displayValue).replace(/,/g, ""); //replace ,
}

11 Comments

It throws [Vue warn]: Error in render: "TypeError: displayValue.replace is not a function" same error with certainperformance.
Please share the output of console.log(displayValue)
Updated my question with snipped result.
try displayValue = String(displayValue).replace(/,/g, "");
Use includes, displayValue.includes(".") ...read about includes
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.