The front is written to vue.js At the entrance there is a string variable (monetary value) that comes from the backend. I try to convert it to float, but no conversion takes place. Below is a small sample code.

// Since there is no possibility to provide the server-side code, I will assign the value of the variable

let back_end_value = '0.012'; let local_value = 10; let tmp = 0; let variable = 0; 

I check types:

 console.log('BACK: ', typeof(back_end_value)); // String console.log('local_value: ', typeof(local_value)); // Integer 

All right it should be. Now I convert the string value to a decimal value, and again check the type

 variable = parseFloat(back_end_value).toFixed(8); //Мне нужны 8 знаков после запятой console.log('BACK: ', typeof(variable)); // String 

I get the String type again. How can this be?

As a result, when adding, I see the following result:

 tmp = local_value + back_end_value console.log('Result: ', temp); // 10.0.0012 

Tell me where is my mistake?

    1 answer 1

    The error is that toFixed returns a string , not a "decimal value"

    • Super! Thank!!! You really helped! - Alex