I have been trying to do a very easy thing and it's taking me hours. I can't seem to find a good answer to this question.
I have various numbers, I need to keep only up until the third digit after the decimal. But, if there are trailing zero on the right, remove them. For example:
0.015356 -> 0.015
0.015000 -> 0.015
0.010320 -> 0.01
0.000320 -> 0
I have the numbers as float/double. I need to pass them into another function which will then print them. I don't have control over the other function. I can pass either numbers or strings, and they will get printed accordingly.
I suppose I need to pass on a string, cause otherwise it can't be achved?
I was able to remove the digits up until the third:
num = floor(num*1000)/1000;
0.015356 -> 0.015000
0.000320 -> 0.000000
But now I have the problem of the trailing zero.
In short, how can I achieve what I need?