Setup
Write a function that takes a number and returns the number of significant figures in a given number.
Significant Figures are the...
For further actions, you may consider blocking this person and/or reporting abuse
Shouldn't it be the other way around?
I just checked on Wikipedia and it is right the way that it is stated in the task. This is because if you add zeros after the decimal point, you imply that your number was "measured" with a higher precision.
Example: a normal ruler vs. a precision measuring devices
If you use the normal ruler you can only be certain your measured distance is 1.5cm
With a precision ruler you can be certain, that your measured distance is something like 1.500cm
Oh, so it's a measurement thing.
Interestingly enough, technically, according to Wikipedia we have no way of knowing whether any zero to the right of the last non-zero digit is significant or not, regardless of the presence of decimals. So the exercise is still not quite right.
I feel like the exercise is fine. It defines a definite rule for deciding on which trailing zeros are significant and which aren't.
Yes, but I suppose it's changed to avoid the obvious
string -> number -> string
conversion that would take care of non-significant zeros.Well actually, no. See my response :D
Still doesn't explain why "Trailing zeroes in a number without a decimal point" are not significant, considering how each such zero increases the number by an order of magnitude and how appending
.0
suddenly makes these zeroes significant.Check the Wikipedia article it explains that aswell. Short answer is, that trailing zeros are somewhat ambiguous and that you have to specify it by some rule, which is done by the task description.
Nim submission.
in python
note: added the 11 and 1.1 test cases because the subtracting-from-both-ends solution can have edge cases around there
I think this should do the trick, I'll test it later.
JavaScript
js solution :)
Good point! I didn’t account for trailing 0’s. I’ll update it later.