I want to check if a float32 has two decimal places or not. My javascript way to do this would look like:
step := 0.01
value := 9.99
if int(value/step) % 1 == 0 {
printf("has two decimal places!")
}
The above example also works. However it will not work when step is incorrect as go then cannot properly cast from float64 to int.
Example:
step := 0.1
value := 9.99
if int(value/step) % 1 == 0 {
printf("has two decimal places!")
}
Compiler Error: constant 9.99 truncated to integer
When we use dynamic values it will just return true for every case.
So what is the appropriate way to count decimal places?