1
Good afternoon, Vue.JS can calculate directly in mustache {{}} but when a value comes with comma, Nan appears the result that is, if the variable is value = 2 and I do {{ value - 1 }} it displays 1 of good but if I do value = 2.5 and then {{ value - 1 }} it displays Nan
<p>{{ valor - 2 }}</p>
how could I calculate this comma value in mustaches?
Is it just the comma you really need to treat? What kind of values do you want to accept in these fields? Vale
1.500,R$ 1.500,00,1,6%etc.?– bfavaretto
You could use the raw value for calculation and a filter for display, so you wouldn’t have to treat the comma
– Denis Rudnei de Souza
@bfavaretto yes, the comma, is very basic, the variable gets 4.5 and need to show 3.5 actually
– flourigh
@Denisrudneidesouza is that the gross value is 4.5
– flourigh
You could use the function
replace, ex:number.replace(',', '.'), but will return aString, which can cause strange behaviors– Denis Rudnei de Souza
If
valoris a string it makes no sense to make calculations with the variable in mustaches. It will only obscure your code and/or generate gambiarras. The variablevalorshould be thefloat, who will make this conversion depends on you, but the mustaches does not roll...– fernandosavio
@fernandosavio is an information at the top of the page that I want to repeat in several places but in 1 place it needs to subtract a certain value, I know it is obscure and bizarre, is that I do not dominate, I am studying and I came across this gap
– flourigh
Then at that particular place you can do the conversion, calculate and then convert back to string. You can do this at
methods()if you want.– fernandosavio
@fernandosavio then I would go there where is the method() or create one that receives the Comma, switch to Point and Return with Comma, would be this?
– flourigh
I’ll post an example, could be with
methodwithfilter, go of yourself– fernandosavio
@fernandosavio very Valew friend
– flourigh