0

I'm filtering with vuejs, only the output I want is written in the ".00" span in the comma. how can i do it?

html

1.500 ,00

component

<p class="amount">{{ 1500 | toTL }}</p>

filter

Vue.filter('toTL', function (value) {
    return new Intl.NumberFormat('tr-TR', { currency: 'TRY', minimumFractionDigits: 2}).format(value);
});

output

1.500,00
Tuana
  • 25
  • 5
  • So, exactly what do you want to do? Are you getting1500,00 from API and you want 1500 in the

    and withing that the ,00 in the span?

    – bgeertsema2000 Dec 07 '21 at 13:06
  • I want something like,I want the comma separated field to be written as a span in p. – Tuana Dec 07 '21 at 13:16

1 Answers1

0

I declared you value in the data() function like so :

data () {
    return {
        number: '1500,00',
        newNumber: [],
    }
},

What I did to make this work is make a created function like so :

created() {
    this.newNumber = this.number.split(',')
},

Then, in the frontend (your p and span) :

<p>{{ newNumber[0] }}<span>,{{newNumber[1]}}</span></p>

What I did is turn a value into an array by using the split() function.

There is probably a way better solution but this is what I came up with in a short amount of time, I hope it helps.

  • like this, when I send filter (1500), the data returned to me is "1.500.00". I want to add a new span after this value, comma and comma. You completely misunderstood. – Tuana Dec 07 '21 at 13:33
  • Well, yeah. I asked for clarification but I didnt recieve any new information. But still, you could split your returned value (1500,00) to a new array and return that. – bgeertsema2000 Dec 07 '21 at 13:35
  • [link](https://stackoverflow.com/a/16233919/17426666) new style – Tuana Dec 07 '21 at 13:37