Let's say you want to convert from degrees to radians:
radians = degrees * (pi / 180)
If pi is considered a constant for the purpose of this calculation, then the resulting radians value should have the same number of significant digits as the initial degrees. I.E.
-32.39 degrees = -0.5653 radians # 4 significant digits
-32.38795 degrees = -0.5652763 radians # 7 significant digits
I was surprised that I couldn't find any examples in any language of how to perform this seemingly simple operation.
My first thought is to:
degrees_str = degrees
# remove any non-significant leading zeros from degrees_str
# degree_digits = count the remaining digit characters in degrees_str
# radian_int_digits = count the digits in integer portion of the radians
# round radians to (degree_digits - radian_int_digits) digits after the decimal point
Is that the most efficient manner in performing this general type of calculation (not specific to degrees/radians)?