Function to determine if two numbers are nearly equal when rounded to n significant decimal digits

前端 未结 11 1888

I have been asked to test a library provided by a 3rd party. The library is known to be accurate to n significant figures. Any less-significant errors can safely be

11条回答
  •  执念已碎
    2020-12-03 03:04

    "Significant figures" in decimal is a matter of adjusting the decimal point and truncating to an integer.

    >>> int(3.1415926 * 10**3)
    3141
    >>> int(1234567 * 10**-3)
    1234
    >>>
    

提交回复
热议问题