Compare the size of two numbers in Vue and want to limit the number of decimal places, you can use the parseFloat function to parse floating point numbers

Compare the size of two numbers in Vue and want to limit the number of decimal places, you can use the parseFloat function to parse floating point numbers

If you want to compare the size of two numbers in Vue and want to limit the number of decimal places, you can use the parseFloat function to parse the floating point number and use the toFixed method to limit the number of decimal places.

In the code you provided, you could rewrite it like this:

if (parseFloat(formData.thisPicking) <= parseFloat(formData.currentNumber).toFixed(2)) {
    
    
  // your code here
}

In this way, formData.currentNumber will be parsed as a floating point number with two decimal places, and then compared with formData.thisPicking.

Note that when using the parseFloat function and the toFixed method, ensure that the values ​​of formData.thisPicking and formData.currentNumber are valid numeric strings. If they are not valid numeric strings, comparison results may be inaccurate.

おすすめ

転載: blog.csdn.net/weixin_48616345/article/details/132392459