简体   繁体   English

根据数字中的第二个数字更改显示值

[英]Changing displayed value depending on a second digit from a number

I have a vue filter and display some values. 我有一个vue filter并显示一些值。 I would like to change the value when the value's last digit is between 2 and 4. I need to have an automatised code so it works for all possible intervals, for example: (22-24, 32-34, 622-624...) . 我想在值的最后一位数字介于2到4之间时更改值。我需要有一个自动代码,以便它适用于所有可能的时间间隔,例如: (22-24, 32-34, 622-624...) I managed to find the last digit of a value: value.toString()[value.toString().length - 1] . 我设法找到了值的最后一位: value.toString()[value.toString().length - 1] I am not sure how to solve this problem, maybe I should come up with a special matematical formula? 我不确定如何解决这个问题,也许我应该提出一个特殊的数学公式?

myfilter: (value): => {
    if(value >= 22 && value <= 24) {
        return 'my new value'
    }
}

You can use the modulus operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder_() 您可以使用模数运算符: https : //developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Remainder_()

myfilter: (value): => {
    if(value % 10 <= 4 && value % 10 >= 2 ) {
        return 'my new value'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM