I am trying to find the value of the 4th decimal place and check if it is a zero or not. If not I was planning on throwing an error message. For example 2.3189. I need to be able to check the value of the 4th decimal which in this case is 9. This is the code I have thus far. It seemed to be working for majority of cases but for example 1.2570. When I do the check for this number it says that the 0 is not a 0. When I do the same check with 1.2580 it says that the 0 is a 0. Any help with this would be greatly appreciated.
!!(submission && (quantity * 10000 % 10) === 0);
I'd do regex checking 4th place after '.' to be zero
var number = 0.554156;
/\.[0-9]{3}0/.test(number.toString())
You could make use of javascript expression for accessing the 4th decimal place since modulus operator has precision issues.
const quantity = 1.2570;
console.log(Number(quantity.toFixed(4).split('.')[1][3]));