I am facing an issue with my code that generates alcohol percentage, resulting in values like 43.000004 which I need to trim down to 43.0, 45.3, etc. However, whenever I try to use any trim/parse functions in JavaScript, my browser ends up freezing.
Below is the code snippet:
incrementAlcohol() {
// Initialize an empty array.
let alcoholData = []
// Iterate through the array from 40 to 95 with increments of 0.1.
for (let i = 40; i <= 95; i + 0.1) {
// Trim the decimal places to 3 digits.
parseFloat(i).toFixed(3)
// Convert it into a string for the autocomplete component.
i.toString()
// Add it to the array.
alcoholData.push({
'id': i,
'name': i + "%"
})
}
// Return the processed alcohol data.
return alcoholData
},