Truncate to specified number of significant figures
It's a simple request. You have a number, e.g. 1.25, and want to truncate it to say 2 significant figures. You specifically need to truncate instead of rounding, i.e. you need to get 1.2 instead of 1.3. How do you do that quickly in Python? Check out this code snippet:
. =
= # make sure it's a float or decimal throws an error
# can't take log10(0) so just return 0
return 0
# if it's negative, determine sigfigs of positive and multiply by -1
return -1 *
# normal positive case
=
return